[23336] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5556 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 24 14:10:49 2003

Date: Wed, 24 Sep 2003 11:10:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 24 Sep 2003     Volume: 10 Number: 5556

Today's topics:
    Re: Split variable into fields ? <jurgenex@hotmail.com>
    Re: Split variable into fields ? <abigail@abigail.nl>
    Re: Split variable into fields ? <no.name@eidosnet.co.uk>
    Re: Split variable into fields ? <syscjm@gwu.edu>
    Re: Split variable into fields ? <michael.benton@adpcl.co.uk>
    Re: Split variable into fields ? <xx087@freenet.carleton.ca>
    Re: Split variable into fields ? <REMOVEsdnCAPS@comcast.net>
    Re: Split variable into fields ? <no.name@eidosnet.co.uk>
    Re: Split variable into fields ? <flavell@ph.gla.ac.uk>
        Text::Wrap::wrap difference <agw@cs.columbia.edu>
        Why do these "?:" conditionals work differently? (malgosia askanas)
    Re: Why do these "?:" conditionals work differently? <jaspax@u.washington.edu>
    Re: Why do these "?:" conditionals work differently? <bdonlan@users.sf.net>
    Re: Why do these "?:" conditionals work differently? <xx087@freenet.carleton.ca>
    Re: wtf is the deal? <no.name@eidosnet.co.uk>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 24 Sep 2003 15:05:54 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Split variable into fields ?
Message-Id: <mpicb.2448$FH3.1491@nwrddc02.gnilink.net>

Michael Benton wrote:
> I have a variable which is set to "A..A_B..B_C..C_D..D_123456"
> I would like to split this into fields using the "_" as a field
> delimeter (easy in awk and ksh)
>
> Is there a way to do this in perl ? is there an equiv to teh awk
> "-F_" ?

We must be back to this time of the year where people are asking
self-anwering questions.
Please see "perldoc -f split" and/or http://www.ginini.com/perlsaq.html

jue




------------------------------

Date: 24 Sep 2003 15:26:57 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Split variable into fields ?
Message-Id: <slrnbn3du1.d3q.abigail@alexandra.abigail.nl>

Michael Benton (michael.benton@adpcl.co.uk) wrote on MMMDCLXXVI September
MCMXCIII in <URL:news:3f71a503$1@news.star.co.uk>:
%%  I am new to perl so appoligies in advance.
%%  
%%  I have a variable which is set to "A..A_B..B_C..C_D..D_123456"
%%  I would like to split this into fields using the "_" as a field delimeter
%%  (easy in awk and ksh)
%%  
%%  Is there a way to do this in perl ? is there an equiv to teh awk "-F_" ?


Yeah, perl also has a -F switch, taking a regex as argument.

For details, consult the 'perlrun' manual page.


Abigail
-- 
A perl rose:  perl -e '@}-`-,-`-%-'


------------------------------

Date: Wed, 24 Sep 2003 15:26:30 +0000 (UTC)
From: "D Borland" <no.name@eidosnet.co.uk>
Subject: Re: Split variable into fields ?
Message-Id: <bksd36$bnk$1@titan.btinternet.com>

Man, i've never seen such a such bunch of moaners in one place... everyone
has to throw a dig in whenever they can ... "it must be that time of year"
 ... yeah, like your the all seeing all hearing to i suppose and anyone who
hasn't an intelect superiour to yours, must be picked on.  What was it then
"bullied at school", "can't get it up" or just plain nastiness?

So what if people ask a question you feel is silly, doesn't give you the
right to riddicule them.  Example - Say your Mum's walking down the street
in an outfit i think is stupid - Do i run over to her start laughing in her
face and publicly embarress her, start making fun of her fashion sense so me
and everyone in the street watching, can have a laugh at her expense? Well ?

I don't think you'd agree with that - (no matter what you say).  If you
think someones asked a stupid question, just don't answer it.  Simple
really.  But no-not some of the people in here, they just can help trying to
make someone else the butt of the joke rather than themselves for once.

It's the same thing with this "top posting" crap.  OK i agree that things
need to have an order, but some people put posters in the newsgroup straight
in their killfile if they do this.  What happens then, if it was an accident
that they replied to the wrong thread in the post.  Does that mean that
because someone might make a simple mistake then there not worthy of any
knowledge you may have?  Anyhow if yous are going to act like children when
this "top posting" happens, then you should really make it clearer to first
time that your gonna take a fit and a huffy then cry and put them in your
killfile and stomp your feet for an hour or so, until someone backs you up
and says there there it's ok.

Alot of yous in here, seem to think that because you know alot about perl
that you are somehow better than people who dont so there not worthy of
anything you can help them with.  So you sit and dig at them instead and put
them in your killfile.  All i can say is "WHAT GOES AROUND COMES AROUND KID"
i can assure you of that.

Thank mother nature for "Kama".

Dagmar


"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:mpicb.2448$FH3.1491@nwrddc02.gnilink.net...
> Michael Benton wrote:
> > I have a variable which is set to "A..A_B..B_C..C_D..D_123456"
> > I would like to split this into fields using the "_" as a field
> > delimeter (easy in awk and ksh)
> >
> > Is there a way to do this in perl ? is there an equiv to teh awk
> > "-F_" ?
>
> We must be back to this time of the year where people are asking
> self-anwering questions.
> Please see "perldoc -f split" and/or http://www.ginini.com/perlsaq.html
>
> jue
>
>


---
This e-mail has been virus scanned and is certified virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/03




------------------------------

Date: Wed, 24 Sep 2003 12:07:34 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: Split variable into fields ?
Message-Id: <3F71C146.4030008@gwu.edu>

Jürgen Exner wrote:
> Michael Benton wrote:
> 
>>I have a variable which is set to "A..A_B..B_C..C_D..D_123456"
>>I would like to split this into fields using the "_" as a field
>>delimeter (easy in awk and ksh)
>>
>>Is there a way to do this in perl ? is there an equiv to teh awk
>>"-F_" ?
> 
> 
> We must be back to this time of the year where people are asking
> self-anwering questions.

Of course.  It's September again, didn't you notice?

> Please see "perldoc -f split" and/or http://www.ginini.com/perlsaq.html
> 
                   Chris Mattern



------------------------------

Date: Wed, 24 Sep 2003 17:15:37 +0100
From: "Michael Benton" <michael.benton@adpcl.co.uk>
Subject: Re: Split variable into fields ?
Message-Id: <3f71b976$1@news.star.co.uk>


"Andreas Kahari" <ak+usenet@freeshell.org> wrote in message
news:slrnbn3ce9.1do.ak+usenet@sdf.lonestar.org...
> In article <3f71a503$1@news.star.co.uk>, Michael Benton wrote:
> > I am new to perl so appoligies in advance.
> >
> > I have a variable which is set to "A..A_B..B_C..C_D..D_123456"
> > I would like to split this into fields using the "_" as a field
delimeter
> > (easy in awk and ksh)
> >
> > Is there a way to do this in perl ? is there an equiv to teh awk "-F_" ?
>
> my @fields = split(/_/, $variable);
>
>
> --
> Andreas Kähäri

Thanks. I thought I might have to use an array.

but, in ksh i can say

a=`echo $variable | awk -F_ '{print $2}'`

so could i say (on one line hopefully)

$a = $(@fields = split(/_/, $variable);)[1];

variable = field 1 of array, whose values are output of split ?

:-)

Mike




------------------------------

Date: 24 Sep 2003 16:44:01 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Split variable into fields ?
Message-Id: <slrnbn3ife.mt5.xx087@smeagol.ncf.ca>

Michael Benton <michael.benton@adpcl.co.uk> wrote:
>  "Andreas Kahari" <ak+usenet@freeshell.org> wrote in message
> > In article <3f71a503$1@news.star.co.uk>, Michael Benton wrote:
> > > I have a variable which is set to "A..A_B..B_C..C_D..D_123456"
> > > I would like to split this into fields using the "_" as a field delimeter
> >
> > my @fields = split(/_/, $variable);
>  
>  but, in ksh i can say
>  a=`echo $variable | awk -F_ '{print $2}'`
>  
>  so could i say (on one line hopefully)
>  $a = $(@fields = split(/_/, $variable);)[1];

Even simpler:   $a = (split /_/, $variable)[1];

$a will be undefined if the _ character does not appear in $variable, so
you should test for that before you use $a.

-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


------------------------------

Date: Wed, 24 Sep 2003 12:02:32 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Split variable into fields ?
Message-Id: <Xns940084A5BDAA6sdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"D Borland" <no.name@eidosnet.co.uk> wrote in
news:bksd36$bnk$1@titan.btinternet.com: 

> Man, i've never seen such a such bunch of moaners in one place...
> everyone has to throw a dig in whenever they can ... "it must be that
> time of year" ... yeah, like your the all seeing all hearing to i
> suppose and anyone who hasn't an intelect superiour to yours, must be
> picked on.  What was it then "bullied at school", "can't get it up" or
> just plain nastiness? 

Surely you must admit that asking what is the perl operator to *split* data 
up into fields is a stupid question?  Or asking what the Perl equivalent to 
awk's -F is?

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP3HOG2PeouIeTNHoEQKhpgCgm50R1OYkB9mM1Fet5cT+dPgnzrYAoJml
D9Tp31Dh6AqgDphMY2T+9L2p
=wDJO
-----END PGP SIGNATURE-----


------------------------------

Date: Wed, 24 Sep 2003 17:10:13 +0000 (UTC)
From: "D Borland" <no.name@eidosnet.co.uk>
Subject: Re: Split variable into fields ?
Message-Id: <bksj5l$2nl$1@hercules.btinternet.com>

Ok, i do, but there's no need to take the piss, for all we know the guy
might be mentally disabled and someone here sits and rips him, mm that's
gotta make his day seem that much brighter.

You are right though, i agree.  But like i tried to say - Just don't answer
it if you think it's stupid.  But hey then again who am i to tell people
right from wrong.  You do whatever you want to do dude :)

Dagmar


> Surely you must admit that asking what is the perl operator to *split*
data
> up into fields is a stupid question?  Or asking what the Perl equivalent
to
> awk's -F is?



---
This e-mail has been virus scanned and is certified virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/03




------------------------------

Date: Wed, 24 Sep 2003 18:31:44 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Split variable into fields ?
Message-Id: <Pine.LNX.4.53.0309241830580.22774@ppepc56.ph.gla.ac.uk>

On Wed, 24 Sep 2003, Chris Mattern wrote:

> Of course.  It's September again, didn't you notice?

As if it wasn't always September on usenet nowadays...


------------------------------

Date: 24 Sep 2003 11:22:37 -0400
From: Art Werschulz <agw@cs.columbia.edu>
Subject: Text::Wrap::wrap difference
Message-Id: <ylay8wefbya.fsf@sobolev.cs.columbia.edu>

Hi.

# Article reposted ... I cancelled it when I thought I had figured out
# the answer ...

I have moved from a Solaris box (running perl 5.6.0) to an Intel Linux
box (running perl 5.8.0).

I have a script that processes msgs I get from certain mailing lists
(which procmail kindly puts into files for me).  It wordwraps the msgs
(since some of them have ridiculously long lines) and replaces certain
encoded chars by their plain text equivalents.  It looks like this

%<------%<--%<--%<---cut here---%<--%<--%<----------------------------
use Text::Wrap;

$Text::Wrap::columns = 79;

while (<>) {
    s/\c]/\"/g;
    s/\cA//g;
    s/\cS/--/g;
    s/\cY/\'/g;
    s/=$//;
    s/=20//;
    s/=85/.../g;
    s/=91/\'/g;
    s/=92/\'/g;
    s/=93/\"/g;
    s/=94/\"/g;
    s/=96/--/g;
    s/\205/.../g;
    s/\221/\'/g;
    s/\222/\'/g;
    s/\223/\"/g;
    s/\224/\"/g;
    s/\226/--/g;
    s/\227/.../g;
    s/\255/--/g;
    $_ = wrap("", "", $_) unless /^[^\s]+:\s/;
    print $_;
}
%<------%<--%<--%<---cut here---%<--%<--%<----------------------------

I want blank lines to remain in the text.  When running this script on
the Solaris box, the blank lines are maintained.  However, they
disappear if I run this script on the Linux box.

Why the difference between these platforms?  Has something changed
between versions 5.6 and 5.8?  

I would appreciate suggestions for making this work on the Linux box.

Thanks. 

-- 
Art Werschulz (8-{)}   "Metaphors be with you."  -- bumper sticker
GCS/M (GAT): d? -p+ c++ l u+(-) e--- m* s n+ h f g+ w+ t++ r- y? 
Internet: agw@cs.columbia.edu<a href="http://www.cs.columbia.edu/~agw/">WWW</a>
ATTnet:   Columbia U. (212) 939-7060, Fordham U. (212) 636-6325


------------------------------

Date: 24 Sep 2003 13:07:54 -0400
From: ma@panix.com (malgosia askanas)
Subject: Why do these "?:" conditionals work differently?
Message-Id: <bksj1a$bgj$1@panix1.panix.com>

In perl5.6.1, this code:

   $DEBUG = 1;
   $DEBUG ? $prefix = 'foo' : $prefix = 'bar';
   print $prefix

prints "foo", even though $DEBUG is set to 1.  On the other hand, this code:

   $DEBUG = 1;
   $DEBUG ? print "foo\n" : print "bar\n";

prints "foo", as I would expect it to (and prints "bar" if $DEBUG is set to 0).
Why doesn't the first piece of code set $prefix to "bar"?


Many thanks in advance,
-malgosia


------------------------------

Date: Wed, 24 Sep 2003 10:32:23 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: Why do these "?:" conditionals work differently?
Message-Id: <Pine.A41.4.58.0309241029440.97024@dante14.u.washington.edu>

malgosia askanas sikyal:

> In perl5.6.1, this code:
>
>    $DEBUG = 1;
>    $DEBUG ? $prefix = 'foo' : $prefix = 'bar';
>    print $prefix
>
> prints "foo", even though $DEBUG is set to 1.  On the other hand, this code:

Eh? This is exactly what it should do. $DEBUG is true, so the code between
? and : is executed, making $prefix equal 'foo'. If $DEBUG is *false*,
then we expect $prefix to be 'bar'.

>    $DEBUG = 1;
>    $DEBUG ? print "foo\n" : print "bar\n";
>
> prints "foo", as I would expect it to (and prints "bar" if $DEBUG is set to 0).
> Why doesn't the first piece of code set $prefix to "bar"?

These two pieces of code work exactly the same. The first piece of code
doesn't set $prefix to "bar" because $DEBUG is true.

--
Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog

Jesus asked them, "Who do you say that I am?"

And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."

And Jesus said, "What?"


------------------------------

Date: Wed, 24 Sep 2003 13:32:39 -0400
From: bd <bdonlan@users.sf.net>
Subject: Re: Why do these "?:" conditionals work differently?
Message-Id: <n21941-o64.ln1@bd-home-comp.no-ip.org>

malgosia askanas wrote:

> In perl5.6.1, this code:
> 
>    $DEBUG = 1;
>    $DEBUG ? $prefix = 'foo' : $prefix = 'bar';
>    print $prefix
> 
> prints "foo", even though $DEBUG is set to 1.  On the other hand, this
> code:
> 
>    $DEBUG = 1;
>    $DEBUG ? print "foo\n" : print "bar\n";
> 
> prints "foo", as I would expect it to (and prints "bar" if $DEBUG is set
> to 0). Why doesn't the first piece of code set $prefix to "bar"?

Why wouldn't it? You didn't change the order, so it should work the same
way.
-- 
Hard work never killed anybody, but why take a chance?
                -- Charlie McCarthy



------------------------------

Date: 24 Sep 2003 17:50:14 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Why do these "?:" conditionals work differently?
Message-Id: <slrnbn3mbj.npd.xx087@smeagol.ncf.ca>

malgosia askanas <ma@panix.com> wrote:
>  In perl5.6.1, this code:
>  
>     $DEBUG = 1;
>     $DEBUG ? $prefix = 'foo' : $prefix = 'bar';
>     print $prefix
>  
>  prints "foo", even though $DEBUG is set to 1.  On the other hand, this code:
>  
>     $DEBUG = 1;
>     $DEBUG ? print "foo\n" : print "bar\n";
>  
>  prints "foo", as I would expect it to (and prints "bar" if $DEBUG is set to 0).
>  Why doesn't the first piece of code set $prefix to "bar"?

The ?: operator has higher precedence than =, so I think your first
example is equivalent to
    ($DEBUG ? $prefix = 'foo' : $prefix) = 'bar';
Which evaluates to 
    $prefix = 'foo' = 'bar';

You probably want:
    $prefix = $DEBUG ? 'foo' : 'bar';

-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


------------------------------

Date: Wed, 24 Sep 2003 17:15:54 +0000 (UTC)
From: "D Borland" <no.name@eidosnet.co.uk>
Subject: Re: wtf is the deal?
Message-Id: <bksjga$3a6$1@hercules.btinternet.com>

> If you travelled to Britain, would you insist on driving on the
> right-hand side of the road?  After all, it's just a convention, and
> those silly Brits will surely see the light after you show them how
> to drive properly.  What would actually happen, though, is that
> everyone would honk at you and you would cause a wreck.
>
> Stop driving on the wrong side of the road.
>
> --
> David Wall


Silly brits... hah!

 i take it your your a yankee twat?

Americans - The most hated race in the world!

Yous blow kids up you sick bast%rds - No-one every other country with a
nuclear warhead has it pointed at yous.

Dagmar


---
This e-mail has been virus scanned and is certified virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/03




------------------------------

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5556
***************************************


home help back first fref pref prev next nref lref last post