Gossamer Forum
Home : General : Perl Programming :

Re: [petermcdonald] Setting specific line in file as variable

Quote Reply
Re: [petermcdonald] Setting specific line in file as variable In reply to
Hi Peter,

There's at least a couple of ways you can do that.

1) Do a 'foreach' loop, "next"ing any line that doesn't start with the $goto variable you set. Ex:
foreach $line(@lines) {
next unless ($line=~/^$goto/);
### do your stuff if it matches
last; # prevents further parsing of later lines, if you've already found the line you were looking for
}

OR

use the 'seek' method. I'm not real well-versed, because I only hacked it into an existing script some years ago. Search the perl pages for examples of 'seek'ing.

Hope this helps.
Subject Author Views Date
Thread Setting specific line in file as variable petermcdonald 6410 Sep 1, 2002, 4:21 PM
Thread Re: [petermcdonald] Setting specific line in file as variable
durp 6282 Sep 1, 2002, 10:08 PM
Thread Re: [durp] Setting specific line in file as variable
petermcdonald 6289 Sep 1, 2002, 10:50 PM
Thread Re: [petermcdonald] Setting specific line in file as variable
petermcdonald 6282 Sep 1, 2002, 11:06 PM
Thread Re: [petermcdonald] Setting specific line in file as variable
Paul 6266 Sep 2, 2002, 2:10 AM
Post Re: [Paul] Setting specific line in file as variable
durp 6260 Sep 2, 2002, 10:31 AM
Thread Re: [Paul] Setting specific line in file as variable
petermcdonald 6250 Sep 2, 2002, 10:34 AM
Thread Re: [petermcdonald] Setting specific line in file as variable
petermcdonald 6273 Sep 2, 2002, 10:37 AM
Post Re: [petermcdonald] Setting specific line in file as variable
Paul 6266 Sep 2, 2002, 10:50 AM
Thread Re: [petermcdonald] Setting specific line in file as variable
Paul 6226 Sep 2, 2002, 10:56 AM
Thread Re: [Paul] Setting specific line in file as variable
petermcdonald 6244 Sep 2, 2002, 11:07 AM
Thread Re: [petermcdonald] Setting specific line in file as variable
Paul 6243 Sep 2, 2002, 11:34 AM
Thread Re: [Paul] Setting specific line in file as variable
petermcdonald 6256 Sep 2, 2002, 11:55 AM
Thread Re: [petermcdonald] Setting specific line in file as variable
Paul 6249 Sep 5, 2002, 4:21 AM
Post Re: [Paul] Setting specific line in file as variable
petermcdonald 6208 Sep 7, 2002, 6:07 PM