LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 03: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, 02:51 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
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, 03:34 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 10: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, 12:45 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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, 04:23 PM   #6
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
Thanks for the link! I hadn't found any docs about that.
 
Old 10-25-2013, 01: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, 03: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



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 08:59 AM
grep for words with special characters dwezel Linux - General 5 07-07-2012 03:23 PM
LXer: Associating Images with Words in Moodle 1.9 for Special kids LXer Syndicated Linux News 0 07-17-2010 01:11 PM
Perl, substituting words in file - last line copied! pingu Programming 4 11-29-2009 06:11 AM
VIM: How to delete all lines that include special words. cryincold Linux - Software 3 02-09-2008 11:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:14 PM.

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
Open Source Consulting | Domain Registration