in reply to reading from a file and splitting

You could also access the data with a regex like this:

/==/

Then, you've broken the line into three parts: the part before the ==, the ==, and the part after. Assuming that == matches in the line, you can access these parts thus:

$` = the part before the ==

$& = "=="

$' = the part after the ==

the first example of split may be more appropriate for this type of thing though.

okay apparently I can't read questions either. Didn't see you _just_ wanted string(s) beginning with hi. My example would be more appropriate if, for some reason, you wanted this plus other, similarly formatted data;)

Replies are listed 'Best First'.
Re: Re: reading from a file and splitting
by jweed (Chaplain) on Jan 17, 2004 at 01:39 UTC
    Since the use of these three variables causes such a huge program-wide performance hit, I would definately shy away from using them in a situation like this where split is so ideal.



    Code is (almost) always untested.
    http://www.justicepoetic.net/
      thank you, this is what i ended up with:
      open (file, "<file.txt"); @file = <file>; close (file); foreach $line(@file){ ($var1, $var2) = split(/\=\=/, $line); if($chat =~ /\b$var1\b/i){ #the item i was looking for print "$var2"; }