SPUG: Should I not do while (<FOO> !~ /^mailboxes/) { } ?
Chris Wilkes
cwilkes at ladro.com
Fri Feb 22 17:01:11 CST 2002
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 "#$_" } <>';
I'm just trying to scan down through .muttrc for the line that starts
with "mailboxes" and I'm currently doing it the way Matt Tucker has with
a simple
while (<FOO>) {
last if (/^mailboxes/);
}
print if ($_);
which is fine. The grep you had works even better if I had two ^mailboxes
lines in there. I'm a little leary about using grep like this as it
sucks in all of <FOO> into a big array and then goes over it. But I
know this file is only going to be a couple dozen lines so I'm fine.
Chris
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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