Ask a Question related to PERL Beginners, Design and Development.
-
Jan Eden #1
Two-liner to one-liner
Hi all,
I tried to stuff the following two lines into one, but did not succeed:
my($teilnehmer) = $eingabe =~ m/(?<=Teilnehmer:\n\n)(.+)/s;
my(@teilzeilen) = split /\n/, $teilnehmer;
This does not work:
my @teilnehmer = $eingabe =~ m/(?<=Teilnehmer:\n\n)(.+)/s;
This does neither:
my @teilnehmer = split /\n/, $eingabe =~ m/(?<=Teilnehmer:\n\n)(.+)/s;
Any ideas?
Thanks,
Jan
--
How many Microsoft engineers does it take to screw in a lightbulb? None. They just redefine "dark" as the new standard.
Jan Eden Guest
-
scrambler one-liner
I just came across this interesting article at Slashdot that explains that according to some English university the order of letters in words are... -
eval parameters one liner
I know I saw something like this in the past I just can't find it. Anyone got any ideas? perl -e 'print eval { @ARGV }, "\n"' 5 + 5 it should... -
Hm... nice, Euclid is a one-liner
a, b = b, a % b while b != 0 That's what I like about Ruby. The Perl equivalent is, of course: ($a, $b) = ($b, $a % $b) while $b; Is... -
can this one-liner be squeezed any shorter?
On Sun, 27 Jul 2003, Dan Jacobson wrote: Well, you ARE hardwiring $q's value. Or do you mean using the expression instead of $q? You... -
Need a quick one-liner
Hi everybody I have some data files in the following format: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 .... -
John W. Krahn #2
Re: Two-liner to one-liner
Jan Eden wrote:
Hello,>
> Hi all,
> I tried to stuff the following two lines into one, but did not succeed:
>
> my($teilnehmer) = $eingabe =~ m/(?<=Teilnehmer:\n\n)(.+)/s;
> my(@teilzeilen) = split /\n/, $teilnehmer;
>
> This does not work:
>
> my @teilnehmer = $eingabe =~ m/(?<=Teilnehmer:\n\n)(.+)/s;
>
> This does neither:
>
> my @teilnehmer = split /\n/, $eingabe =~ m/(?<=Teilnehmer:\n\n)(.+)/s;
>
> Any ideas?
my @teilnehmer = map /.+/g, $eingabe =~ m/(?<=Teilnehmer:\n\n)(.+)/s;
John
--
use Perl;
program
fulfillment
John W. Krahn Guest
-
Charles K. Clarkson #3
RE: Two-liner to one-liner
Jan Eden <lists@jan-eden.de> wrote:
:
: I tried to stuff the following two lines into one, but did
: not succeed:
:
: my($teilnehmer) = $eingabe =~ m/(?<=Teilnehmer:\n\n)(.+)/s;
: my(@teilzeilen) = split /\n/, $teilnehmer;
Care to share a typical value for $eingabe with us?
How about:
my @teilzeilen = split /\n/, ( $eingabe =~ /(?<=Teilnehmer:\n\n)(.+)/s )[0];
I think(?) "( $eingabe =~ /(?<=Teilnehmer:\n\n)(.+)/s )[0]"
is forcing the regex into list context. In scalar context it
returns 1 (for success?) and split assumes scalar context of
its second argument.
HTH,
Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328
Charles K. Clarkson Guest
-
Tim Johnson #4
RE: Two-liner to one-liner
Just a small correction: In scalar context it returns 1 because there
is 1 element in the list. If there were more parentheses it might
return a higher number.
-----Original Message-----
From: Charles K. Clarkson [mailto:cclarkson@htcomp.net]
Sent: Wednesday, January 28, 2004 6:13 PM
To: 'Jan Eden'; 'Perl Lists'
Subject: RE: Two-liner to one-liner
I think(?) "( $eingabe =~ /(?<=Teilnehmer:\n\n)(.+)/s )[0]"
is forcing the regex into list context. In scalar context it returns 1
(for success?) and split assumes scalar context of its second argument.
Tim Johnson Guest
-
Jeff 'Japhy' Pinyan #5
Re: Two-liner to one-liner
On Jan 27, Jan Eden said:
As far as I can tell, there is no need for a look-behind in this regex.>my($teilnehmer) = $eingabe =~ m/(?<=Teilnehmer:\n\n)(.+)/s;
my ($teilnehmer) = $eingabe =~ /Teilnehmer:\n\n(.+)/s;
should be sufficient.
As for shrinking them>my(@teilzeilen) = split /\n/, $teilnehmer;
my @teilzeilen = split /\n/, ($eingabe =~ /Teilnehmer:\n\n(.+)/s)[0];
should work.
--
Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
Jeff 'Japhy' Pinyan Guest
-
Jan Eden #6
RE: Two-liner to one-liner
Thanks for all the suggestions. This is a very helpful list.
Charles K. Clarkson wrote:
It's just a bunch of text. The string "Teilnehmer:\n\n" appears just beforethe list of attendants (which I want to extract).>Jan Eden <lists@jan-eden.de> wrote:
>:
>: I tried to stuff the following two lines into one, but did
>: not succeed:
>:
>: my($teilnehmer) = $eingabe =~ m/(?<=Teilnehmer:\n\n)(.+)/s;
>: my(@teilzeilen) = split /\n/, $teilnehmer;
>
> Care to share a typical value for $eingabe with us?
>
Ah! I knew about regex results in scalar and list context, but I took the @teilzeilen to define a list context, while in fact split defines the context. My fault.> How about:
>
>my @teilzeilen = split /\n/, ( $eingabe =~ /(?<=Teilnehmer:\n\n)(.+)/s )[0];
>
> I think(?) "( $eingabe =~ /(?<=Teilnehmer:\n\n)(.+)/s )[0]"
>is forcing the regex into list context. In scalar context it
>returns 1 (for success?) and split assumes scalar context of
>its second argument.
>
BTW, accessing $1 like this implies that $1, $2 ... form an array. How can it be accessed as a whole?
Thanks again,
Jan
--
How many Microsoft engineers does it take to screw in a lightbulb? None. They just redefine "dark" as the new standard.
Jan Eden Guest
-
Jan Eden #7
RE: Two-liner to one-liner
Since 0 is always false and all other numbers are true, the returned numberof elements can indicate success at the same time. My admiration for the the way Larry Wall thinks is growing by the minute.
- Jan
Tim Johnson wrote:
-->
>Just a small correction: In scalar context it returns 1 because there
>is 1 element in the list. If there were more parentheses it might
>return a higher number.
>
>
>
>-----Original Message-----
>From: Charles K. Clarkson [mailto:cclarkson@htcomp.net]
>Sent: Wednesday, January 28, 2004 6:13 PM
>To: 'Jan Eden'; 'Perl Lists'
>Subject: RE: Two-liner to one-liner
>
> I think(?) "( $eingabe =~ /(?<=Teilnehmer:\n\n)(.+)/s )[0]"
>is forcing the regex into list context. In scalar context it returns 1
>(for success?) and split assumes scalar context of its second argument.
>
>
There are 10 kinds of people: those who understand binary, and those who don't
Jan Eden Guest
-
R. Joseph Newton #8
Re: Two-liner to one-liner
Jan Eden wrote:
my @matches = /($regex)/g;>
> BTW, accessing $1 like this implies that $1, $2 ... form an array. How can it be accessed as a whole?
my @matches = /hard-coded random stuff(.*) boilerplate(.*)more unwanted (.*)/;
Joseph
R. Joseph Newton Guest
-
R. Joseph Newton #9
Re: Two-liner to one-liner
"R. Joseph Newton" wrote:
Oooops, sorry, needs a small adjustment, I think:
To put the regex expressions into list context.> Jan Eden wrote:
>>> >
> > BTW, accessing $1 like this implies that $1, $2 ... form an array. How can it be accessed as a whole?
> my @matches =( /($regex)/g);
> my @matches = (/hard-coded random stuff(.*) boilerplate(.*)more unwanted (.*)/);
> Joseph
R. Joseph Newton Guest
-
Jan Eden #10
Re: Two-liner to one-liner
R. Joseph Newton wrote:
Ok, that should have been obvious. Thank you.>"R. Joseph Newton" wrote: Oooops, sorry, needs a small adjustment, I
>think:
>>>Jan Eden wrote:
>>>>>>>
>>>BTW, accessing $1 like this implies that $1, $2 ... form an array.
>>>How can it be accessed as a whole?
>>my @matches =( /($regex)/g);
Doesn't the array on the left already form a list context? Do I really needthe parentheses around the regex part?>To put the regex expressions into list context.
>
- Jan
--
There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson
Jan Eden Guest
-
John W. Krahn #11
Re: Two-liner to one-liner
Jan Eden wrote:
Yes.>
> R. Joseph Newton wrote:
>>> >"R. Joseph Newton" wrote: Oooops, sorry, needs a small adjustment, I
> >think:
> >> >>Jan Eden wrote:
> >>
> >>>
> >>>BTW, accessing $1 like this implies that $1, $2 ... form an array.
> >>>How can it be accessed as a whole?
> >>
> >>my @matches =( /($regex)/g);
> Ok, that should have been obvious. Thank you.
>> Doesn't the array on the left already form a list context?> >To put the regex expressions into list context.
> >
No, no parenthesis are required.> Do I really need the parentheses around the regex part?
my @matches = /$regex/g;
John
--
use Perl;
program
fulfillment
John W. Krahn Guest



Reply With Quote

