Re: Help with $_
by Gabor Szabo other posts by this author
Oct 28 2009 12:43AM messages near this date
Re: Help with $_
|
Problem with missing module
On Wed, Oct 28, 2009 at 1:33 AM, Michael Ellery
<mikee@[...].com> wrote:
> I would recommend either (1) don't chomp in the first place or (2) just
> do print "$_\n".
>
> -Mike
>
> Barry Brevik wrote:
> > I am aware that there are a number of Perl "operations" that will use
> > the system variable $_ as the default variable if one is not supplied.
> >
> > Consider the following snippet (where XMLIN is a previously opened file
> > handle):
> >
> >
> > Â foreach (<XMLIN>)
> > Â {
> > Â Â chomp;
> >
> > Â Â # Do some stuff to the contents of the line.
> >
> > Â Â print;
> > Â }
> >
> > OK, what I really want to do here is print the (possibly changed) line,
> > AND a CR/LF, but to do that, I have to add a separate print statement
> > like this: print "\n";
> >
> > So after all these years, I'm wondering, is there a PERLish way to add a
> > "\n" in the same line of code that prints the default $_ variable?
> >
Starting from Perl 5.10 you can write the following
use 5.010;
say "hello world";
and it will print hello world with a newline at the end.
Gabor
http://szabgab.com/blog.html
_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Barry Brevik
Olivier Mengue
Michael Ellery
Gabor Szabo
|