LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-18-2004, 01:15 PM   #1
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,988
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
perl input field separator


Lasses and Gents,

What special variable in perl holds the input field
separator? Analogous to awk's FS ... I found
references for the record separator(s) and an
output field separator, but nothing about input
field separators ...

Thanks a bunch!


Cheers,
Tink
 
Old 10-18-2004, 01:25 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
$INPUT_RECORD_SEPERATOR
$RS
or even
$/

depending on how clever you are..... or think you are...
 
Old 10-18-2004, 01:27 PM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
erm.. ok you wanted a field seperator... i give up, what's the difference??

and you know i've still
never got round to
understanding quite
why you always seem
to write your posts
just like this.
 
Old 10-18-2004, 02:10 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,988
Blog Entries: 11

Original Poster
Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Quote:
Originally posted by acid_kewpie
erm.. ok you wanted a field seperator... i give up, what's the difference??
I want to write a little script to do analysis on
the current mail-queue and take action on it
if necessary ... every once in a while we get
hit by mails that pass spam-assassins filters
(very conservative settings) and bring postfix
to a crawl ...

The mailq output is a set of multi-line records,
I need to treat 1 or more blank lines as a record
separator, and a simple newline as a field.

The default behaviour of awk and perl would be
to have a line as a record, and whitespace delimited
"words" as fields.


Quote:
and you know i've still
never got round to
understanding quite
why you always seem
to write your posts
just like this.
I do it slightly wider (approximately 60 chars, I found)
and I do it because I find it easier to read and more
pleasant to the eye :)


Cheers,
Tink
 
Old 10-18-2004, 03:34 PM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
Code:
one
one
one

two
two

three
three
three
three

four
plus
Code:
use strict;
open (LIST, "list");
$/ = "\n\n";
my $x;
while (<LIST>) {
  print "=======\n";
  foreach (split "\n", $_) {
    print "++" . $_ . "\n";
  }
}
close LIST;
equals
Code:
=======
++one
++one
++one
=======
++two
++two
=======
++three
++three
++three
++three
=======
++four
that's the sort of split you are after right?
 
Old 10-18-2004, 04:08 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,988
Blog Entries: 11

Original Poster
Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Yep :}

Thanks a truckload! And man, perl sure is
cryptic ;} ... since I'm not 100% certain
whether records will be separated by one
or several blank lines I can even use $/=""
rather than "\n\n" ...

Brilliant!


Cheers,
Tink
 
  


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
Standard Input in Perl Program eachow Linux - General 2 11-17-2005 12:16 AM
My field separator changes when using awk Helene Programming 3 05-01-2004 08:10 AM
PERL question about getting input of current root window image joesbox Programming 3 01-02-2004 02:15 PM
perl input? andox Programming 1 06-25-2003 05:41 AM
console input in perl! farhanali Programming 7 06-12-2003 02:27 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration