SPUG: Should I not do while (<FOO> !~ /^mailboxes/) { } ?

Dean Hudson dean at ero.com
Fri Feb 22 16:56:30 CST 2002


Sorry if my response was mildly incoherent; I was interrupted in the
process of writing it and never fully recovered.

To clarify (just a bit): on the command line output below, the lines
beginning with '#' were generated by the one-liners whereas the lines
not beginning with '#' were typed by me into STDIN.

dean.

On Fri, Feb 22, 2002 at 02:41:43PM -0800, Dean Hudson wrote:
> If you want $_ to get set you should probably do something more like:
> 
> while (<FOO>) {
>     next if /^mailboxes/;
> }
> 
> while (<FOO> !~ /^mailboxes/) does not set implicitly set $_ the way
> you hope.
> 
> It's not really clear to me what you're trying to do exactly. Do you
> want to print the mailboxes line with a prepended # or the other lines
> with a # prepended.
> 
> Here's another way you could do either:
> 
> dean at apogee:~ > perl -e 'grep {/^mailboxes/ && print "#$_" } <>';
> this
> is
> a
> test
> mailboxes
> test
> #mailboxes
> 
> dean at apogee:~ > perl -e 'grep {!/^mailboxes/ && print "#$_" } <>';
> this
> is
> a
> test
> mailboxes
> test
> #this
> #is
> #a
> #test
> #test
> dean at apogee:~ >
> 
> dean.

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list