* Paul Johnson [2008.01.01 22:10]:
The most direct analogy would be to use an
in-memory file:
open my $fh, , \$scalar;
print while $fh;
Very nice. Thanks.
I didn't understand what John and Chas were trying
to say until I saw the term in-memory file.
Exactly the kind of stuff I was hoping
Hi,
I wonder what idioms are available to loop through
the lines stored in a scalar variable. I guess I'm
looking for something analogous to these idioms
for files and arrays respectively:
while(FH) {
# do stuff
}
foreach (@array) {
# do stuff
}
When I had to do this I split the scalar in an
On Dec 31, 2007 5:56 PM, Jean-Rene David [EMAIL PROTECTED] wrote:
Hi,
I wonder what idioms are available to loop through
the lines stored in a scalar variable. I guess I'm
looking for something analogous to these idioms
for files and arrays respectively:
while(FH) {
# do stuff
}
On Dec 31, 2007 2:56 PM, Jean-Rene David [EMAIL PROTECTED] wrote:
When I had to do this I split the scalar in an
array:
@array = split \n, $scalar;
foreach (@array) {
# do stuff
}
What would be some other ways to do this? (This is
purely curiosity.)
This type of curiosity would be well
You can skip the array assignment and just do:
foreach ( split \n, $scalar ) {
...
}
I predict a reply that uses map()... though I think that using a map
isn't really another solution, but just an alternative to the for
loop.
map {stuff}, split \n, $scalar;
But I think the answer is basically
Jean-Rene David wrote:
Hi,
I wonder what idioms are available to loop through
the lines stored in a scalar variable. I guess I'm
looking for something analogous to these idioms
for files and arrays respectively:
while(FH) {
# do stuff
}
foreach (@array) {
# do stuff
}
When I had to do this I
Jean-Rene David wrote:
Hi,
Hello,
I wonder what idioms are available to loop through
the lines stored in a scalar variable. I guess I'm
looking for something analogous to these idioms
for files and arrays respectively:
while(FH) {
# do stuff
}
open FH, '', \$scalar or die Cannot open
On Jan 1, 2008 12:21 PM, yitzle [EMAIL PROTECTED] wrote:
You can skip the array assignment and just do:
foreach ( split \n, $scalar ) {
...
}
I predict a reply that uses map()... though I think that using a map
isn't really another solution, but just an alternative to the for
loop.
map
On Mon, Dec 31, 2007 at 05:56:35PM -0500, Jean-Rene David wrote:
I wonder what idioms are available to loop through
the lines stored in a scalar variable. I guess I'm
looking for something analogous to these idioms
for files and arrays respectively:
while(FH) {
# do stuff
}
foreach
Chas. Owens wrote:
If you have a recent enough version of Perl* you can say
open my $fh, , \$scalar
or die could not attach a file handle to \$scalar: $!;
while (my $line = $fh) {
chomp($line);
#do stuff with $line
}
* 5.8 can do this, but I am not sure about 5.6.*
perldoc -f
10 matches
Mail list logo