Re: Looping through lines stored in a scalar

2008-01-03 Thread Jean-Rene David
* 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

Looping through lines stored in a scalar

2008-01-01 Thread Jean-Rene David
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

Re: Looping through lines stored in a scalar

2008-01-01 Thread Chas. Owens
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 }

Re: Looping through lines stored in a scalar

2008-01-01 Thread Tom Phoenix
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

Re: Looping through lines stored in a scalar

2008-01-01 Thread yitzle
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

Re: Looping through lines stored in a scalar

2008-01-01 Thread Rob Dixon
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

Re: Looping through lines stored in a scalar

2008-01-01 Thread John W. Krahn
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

Re: Looping through lines stored in a scalar

2008-01-01 Thread Chas. Owens
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

Re: Looping through lines stored in a scalar

2008-01-01 Thread Paul Johnson
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

Re: Looping through lines stored in a scalar

2008-01-01 Thread John W. Krahn
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