Would you please tell me about ($a =<STDIN>) !~ /^\s*$/ ? 
Author Message
 Would you please tell me about ($a =<STDIN>) !~ /^\s*$/ ?

Hi,

Would you please let me know about  the following.

===================================
($a =<STDIN>) !~ /^\s*$/
===================================

I would like to know what ($a =<STDIN>) !~ /^\s*$/ means in the following...

while ( ($a =<STDIN>) !~ /^\s*$/){
   ...........

Quote:
}

please let me know...

Thanks

Gabriel



Fri, 13 Jun 2003 17:12:26 GMT  
 Would you please tell me about ($a =<STDIN>) !~ /^\s*$/ ?


Quote:
> Hi,

> Would you please let me know about  the following.

> ===================================
> ($a =<STDIN>) !~ /^\s*$/
> ===================================

> I would like to know what ($a =<STDIN>) !~ /^\s*$/ means in the
following...

> while ( ($a =<STDIN>) !~ /^\s*$/){
>    ...........
> }

This really is a question best answered by comp.lang.perl.misc
newsgroup.

However, it's Xmas!

Keep reading from standard input (i.e. 'usually' an interactive Q & A
session with a user or piped data), store the line read to $a, and do
whatever is within the curly braces. If a blank line is found, exit the
loop.
##############################

Breaking it down;

$a=<STDIN>

Read 'a line' from standard input and store it to $a. Note: This will
depend on your input separator variable $/ which defaults to a newline
character.

!~ /^\s*$/

A regular expression (negated "!"). Read "true" if the variable does NOT
contain ONLY white space (including spaces, tabs, newlines, carriage
returns, formfeeds) from beginning ("^") to end ("$").

so

while (some true expression){
.......do stuff here...

Quote:
}

As soon as a blank line is input (which could just be someone pressing
the return key)...the loop will exit.

Jack

Sent via Deja.com
http://www.deja.com/



Sat, 14 Jun 2003 02:50:37 GMT  
 Would you please tell me about ($a =<STDIN>) !~ /^\s*$/ ?

Quote:

> Hi,

> Would you please let me know about  the following.

> ===================================
> ($a =<STDIN>) !~ /^\s*$/
> ===================================

> I would like to know what ($a =<STDIN>) !~ /^\s*$/ means in the following...

> while ( ($a =<STDIN>) !~ /^\s*$/){
>    ...........
> }

> please let me know...

> Thanks

> Gabriel

Looks like a way to process a file or keyboard input up to the first (or next)
blank line.

($a = <STDIN>) reads a line from the standard input, which may be coming from
the keyboard, a file, etc. and saves it in the variable $a.

!~  operator looks for a failure of  the contents of $a to match the regular
expression
on the right, between the //.

The regular expression specifies a string of characters that consists entirely
(^...$)
of whitespace (\s), zero or more times (*).  I.e. it specifies an empty string
or a string
of spaces, tabs, etc.

Putting that in a while predicate causes the loop to execute repeatedly, reading
lines
from the input.  The body of the while loop will be entered with $a containing
each
line in turn.  The first blank line encountered will cause termination of the
loop.



Mon, 23 Jun 2003 09:06:32 GMT  
 Would you please tell me about ($a =<STDIN>) !~ /^\s*$/ ?

Quote:

>> Hi,

>> Would you please let me know about  the following.

>> ===================================
>> ($a =<STDIN>) !~ /^\s*$/
>> ===================================

>> I would like to know what ($a =<STDIN>) !~ /^\s*$/ means in the following...

>> while ( ($a =<STDIN>) !~ /^\s*$/){
>>    ...........
>> }

>> please let me know...

>> Thanks

>> Gabriel
> Looks like a way to process a file or keyboard input up to the first (or next)
> blank line.
> ($a = <STDIN>) reads a line from the standard input, which may be coming from
> the keyboard, a file, etc. and saves it in the variable $a.
> !~  operator looks for a failure of  the contents of $a to match the regular
> expression
> on the right, between the //.
> The regular expression specifies a string of characters that consists entirely
> (^...$)
> of whitespace (\s), zero or more times (*).  I.e. it specifies an empty string
> or a string
> of spaces, tabs, etc.
> Putting that in a while predicate causes the loop to execute repeatedly, reading
> lines
> from the input.  The body of the while loop will be entered with $a containing
> each
> line in turn.  The first blank line encountered will cause termination of the
> loop.

        I believe it means read and process user input until an empty line (one
containing nothing but spaces, tabs, or other "space" characters) is entered.

Jim



Sat, 28 Jun 2003 02:19:25 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. <<<<<< HELP >>>>>>>>

2. Moron Newbie <<Please Help!>>

3. >>>Please add your Perl Script to the Perlcoders Archive of free scripts <<<<

4. >>>> A Singaporean Girl looking for more penpals!!<<<<<

5. Backspace key and <STDIN>...

6. Input via STDIN without using <CR>

7. <STDIN> in array context

8. Term::Screen and <STDIN>

9. <STDIN> and list or array

10. changing <STDIN>

11. ++ used as <STDIN>

 

 
Powered by phpBB® Forum Software