LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-22-2013, 04:18 PM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
Perl reserved words/special varaibles.


This one liner works great. as soon as it gets to pattern, it stops
and then prints out what i need


Code:
  $ perl -n -e 'next LINE unless /pattern/; print $_'

i got it from: http://www.perl.com/pub/2004/08/09/commandline.html

Question is - LINE - is that a perl special variable?
I don't see it in the special varaible list.
If it is not - how come it does not have a dollar sign in front of it?
 
Old 10-23-2013, 03:51 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,532

Rep: Reputation: 132Reputation: 132
In perl one can easily write programs that work fine but almost no one understands. I think LINE is a file handle but I'm not sure and I don't know how it is created. If you don't get an answer here you can post your question here:
http://perlmonks.org/

The fellows in that forum know all the gory details...
 
Old 10-23-2013, 04:34 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
I don't think LINE is a file handle, it is a label reference.

These 2 do the same thing:
Code:
perl -n -e 'next LINE unless /foo/; print $_' infile
and
Code:
#!/usr/bin/perl
use strict ;
use warnings ;

LINE: while (defined($_ = <ARGV>)) {
    next LINE unless /foo/;
    print $_;
}

exit 0;
I have to admit that I cannot find any documentation or reference to LINE, as stated by j-ray: The perlmonks probably know all the gory details.
 
Old 10-23-2013, 11:22 AM   #4
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
Every time i post something at perlmonks they yell at me (type in all caps) and make me feel like a looser.
 
Old 10-23-2013, 01:45 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
It is documented in the Perl book: https://docs.google.com/viewer?url=h...145_Chap09.pdf

on pages 292 and 293.

The entire chapter goes over how it works - and which options provide the loops.
 
1 members found this post helpful.
Old 10-23-2013, 05:23 PM   #6
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,532

Rep: Reputation: 132Reputation: 132
Thanks for the link! I hadn't found any docs about that.
 
Old 10-25-2013, 02:32 PM   #7
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
It is called a label. like NEXT: GOTO:
a LABEL is a bareward followed by a colon.
 
Old 10-25-2013, 04:56 PM   #8
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
the documentation for the labels is here ;

http://perldoc.perl.org/perlsyn.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kdump reserved memory not getting reserved Rohant Linux - Server 3 07-02-2013 09:59 AM
grep for words with special characters dwezel Linux - General 5 07-07-2012 04:23 PM
LXer: Associating Images with Words in Moodle 1.9 for Special kids LXer Syndicated Linux News 0 07-17-2010 02:11 PM
Perl, substituting words in file - last line copied! pingu Programming 4 11-29-2009 07:11 AM
VIM: How to delete all lines that include special words. cryincold Linux - Software 3 02-10-2008 12:17 AM


All times are GMT -5. The time now is 04:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration