CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Simple question

 



simon
Deleted

Aug 12, 2000, 6:55 PM

Post #1 of 4 (576 views)
Simple question Can't Post

Could someone please explain me what =~ and $| does and a simple example of each and how it can be used for?
Thank you


Tasario
Deleted

Aug 15, 2000, 12:31 PM

Post #2 of 4 (576 views)
Re: Simple question [In reply to] Can't Post

=~ is the redirect operator
if you use /a{3}/ you search $_ for three a.
if you want to search a variable for it
$my_variable =~ /a{3}/
you search this variable for three a
You don't have to copy it to $_.
$| is the same as $OUTPUT_AUTOFLUSH and while non-zero forces a flush after every write on the output channel.
Never used it though ;-)


simon
Deleted

Aug 15, 2000, 9:41 PM

Post #3 of 4 (576 views)
Re: Simple question [In reply to] Can't Post

i don't understand this.


>=~ is the redirect operator
if you use /a{3}/ you search $_ for three a.
if you want to search a variable for it
$my_variable =~ /a{3}/
you search this variable for three a


Kanji
User / Moderator

Aug 16, 2000, 4:47 AM

Post #4 of 4 (576 views)
Re: Simple question [In reply to] Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if ( /a{3}/ ) {</pre><HR></BLOCKQUOTE>
... is really the same as ...
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if { $_ =~ /a{3} ) {</pre><HR></BLOCKQUOTE>
If it helps any, read =~ as 'contains' is followed by a regexp, and 'needs to have' if followed by some sort of manipulation like s/// or tr///.

ie, $var =~ /a word/; - $var contains "a word".

$var =~ s/this word/that word/; - $var needs to have "this word" substituted with "that word".

Also, $| is good to use when you're either want to see things as they happen instead of letting perl spit it out 'whenever' and also when interacting with external programs via system(), etc. as not unbuffering your output means can lead to things being displayed in an unexpected order.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives