Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird One :: deletes fields when writing 1

Status
Not open for further replies.

PaulTEG

Technical User
Sep 26, 2002
4,469
IE
Code:
   print FILE "$eventdate\:\:$sortdate\:\:$event\:\:$description\:\:$location\:\:$special\n";

The code above works, and it took me a while to suss that the code below wasn't, as it was only writing the last field $special

Code:
   print FILE "$eventdate::$sortdate::$event::$description::$location::$special\n";

It looks like the use of unescaped :: colons, was deleting the previous fields. Anyone got any ideas as to why that might be

--Paul

cigless ...
 
Just guessing ... Is unescaped :: being interpreted as the package separator?
 
but it's in quotes???

:bemused:


cigless ...
 
The quotes don't matter. It's the usual interpolating behavior of variable names inside double quotes.
Code:
#!perl
use strict;

my $x = "hey";
print "$foo::$bar::$baz::$x";
prints hey.

From perldoc perlmod:
You can refer to variables and filehandles in other packages by prefixing the identifier with the package name and a double colon: $Package::Variable. If the package name is null, the "main" package is assumed. That is,
$::sail is equivalent to $main::sail.


The old package delimiter was a single quote, but double colon is now the preferred delimiter,
...
Because the old-fashioned syntax is still supported for
backwards compatibility, if you try to use a string
like "This is $owner's house", you'll be accessing
$owner::s; that is, the $s variable in package "owner",
which is probably not what you meant. Use braces to disambiguate, as in "This is ${owner}'s house".


 
Code:
#!perl
use strict;

my $x = "hey";
my ($foo, $bar, $baz) = (1,2,3);

print "$foo::$bar::$baz::$x\n";  [b]#prints "hey"[/b]
print "${foo}::${bar}::${baz}::${x}\n"; [b]#prints "1::2::3::hey"[/b]
 
Mike,

Thanks for that, couldn't understand where my data was going

Cheers
--Paul

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top