Hello.

$/ = Input record seperator, the delimiter Perl expects between the reocrds
it reads from files.  "\n" is default.

Example.  Undefining the record seperator allows you to read in a multiline
file all at once.

undef $/;
open HANDLE, "file.txt";
$text = <HANDLE>;
print $text;


$* = Multi line matching.  This is deprecated.  You should yse the s and m
modifiers with m// and s///.

Example.  If you have the following text with multiple lines.

$_ = "This text\nhas multiple lines.";
s/^/BOL/g; #BOL is beginning of line
s/$/EOL/g; #EOL is end of line
print;

Result: This should print out one line.

if you set $* to 1.  using $ and ^ will match before and after newlines.
The default for $* is 0.

NOTE: Perl usually ignores the newline in the string.
 You can change that by setting $* to 1;


$* = 1;
$_ = "This text\nhas multiple lines.";
s/^/BOL/g; #BOL is beginning of line
s/$/EOL/g; #EOL is end of line
print;

Result: THis should print two lines


Remember $* is deprecated.  You should use the m modifier like this.

$_ = "This text\nhas multiple lines.";
s/^/BOL/mg; #notice the m
s/$/EOL/mg; #notice the m
print;




----- Original Message -----
From: "Perl" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, December 23, 2003 7:04 PM
Subject: Perl defined variables


> Hi,
>   could anybody please illustrate with an example the
> use of the following variables :
>
> $/
> $*
>
> or more specifically here is the code i have.
> what exactly would the following accomplish ?
>
> $/ = "Begin";
> $* = 1 ;
>
> while (<>) {
>    if (/$pattern/){
>      print;
>   }
>  }
>
> my understanding is
>  $/ = "Begin"
> treats the word "Begin"as delimiter instead of "\n"
> and treats the entire content between two "Begin" s as
> one single line.
>
> how does setting "$*" to a particular value alter
> anything here  ? hope i am making myself clear ....
>
> thanks,
> S.
>
>
>
>
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to