[31341] in Perl-Users-Digest
Perl-Users Digest, Issue: 2586 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 7 11:09:48 2009
Date: Mon, 7 Sep 2009 08:09:11 -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 Mon, 7 Sep 2009 Volume: 11 Number: 2586
Today's topics:
Re: Cookies [Firefox/IE] <Andrzej.Filip@gmail.com>
Re: Cookies [Firefox/IE] <wassupme@gmail.com>
Re: Cookies [Firefox/IE] <claus.kick@googlemail.com>
Re: Cookies [Firefox/IE] greymausg@mail.com
Cookies <wassupme@gmail.com>
Re: copy specific lines <derykus@gmail.com>
Re: copy specific lines <derykus@gmail.com>
Re: copy specific lines sln@netherlands.com
FAQ 1.2 Who supports Perl? Who develops it? Why is it <brian@theperlreview.com>
FAQ 3.12 Where can I get perl-mode for emacs? <brian@theperlreview.com>
FAQ 3.9 Is there a ctags for Perl? <brian@theperlreview.com>
FAQ 4.10 Why aren't my random numbers random? <brian@theperlreview.com>
FAQ 4.42 How can I tell whether a certain element is co <brian@theperlreview.com>
join lines - perl command <julia_2683@hotmail.com>
Re: join lines - perl command <bugbear@trim_papermule.co.uk_trim>
Re: join lines - perl command (Greg Bacon)
Query about viewing web pages. <orion.osiris@virgin.net>
Re: Why does "$v = @ARGV[0]" work ? <rlfoster2424@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 07 Sep 2009 01:09:51 +0200
From: Andrzej Adam Filip <Andrzej.Filip@gmail.com>
Subject: Re: Cookies [Firefox/IE]
Message-Id: <ctqr61ct08-996@michael.brudna.chmurka.net>
wassup <wassupme@gmail.com> wrote:
> hi. is there a way to convert a FF/IE cookie into using it with
> mechanize? cuz, i want to login a site that uses recaptcha, and
> mechanize can't login that way, so i was thinking of using a cookie
> that would make the site think i was already logged in, skiping the
> login process.. is this possible? if yes, how can it be done? thanks
> in advance!
Have you tried to use HTTP::Cookies::Mozilla (For firefox) or
HTTP::Cookies::Microsoft (or IE) provided at CPAN.org?
According to description it should deliver what you want.
--
[pl>en Andrew] Andrzej Adam Filip : anfi@onet.eu : Andrzej.Filip@gmail.com
But it does move!
-- Galileo Galilei
http://groups.google.com/groups?selm=ctqr61ct08-996@michael.brudna.chmurka.net
------------------------------
Date: Sun, 6 Sep 2009 16:39:15 -0700 (PDT)
From: wassup <wassupme@gmail.com>
Subject: Re: Cookies [Firefox/IE]
Message-Id: <8aef7159-f441-4b5c-af49-a595ce64ba21@y21g2000yqn.googlegroups.com>
On Sep 7, 12:09=A0am, Andrzej Adam Filip <Andrzej.Fi...@gmail.com>
wrote:
> wassup <wassu...@gmail.com> wrote:
> > hi. is there a way to convert a FF/IE cookie into using it with
> > mechanize? cuz, i want to login a site that uses recaptcha, and
> > mechanize can't login that way, so i was thinking of using a cookie
> > that would make the site think i was already logged in, skiping the
> > login process.. is this possible? if yes, how can it be done? thanks
> > in advance!
>
> Have you tried to use HTTP::Cookies::Mozilla (For firefox) or
> HTTP::Cookies::Microsoft (or IE) provided at CPAN.org?
>
> According to description it should deliver what you want.
>
> --
> [pl>en Andrew] Andrzej Adam Filip : a...@onet.eu : Andrzej.Fi...@gmail.co=
m
> But it does move!
> =A0 -- Galileo Galilei
> http://groups.google.com/groups?selm=3Dctqr61ct08-...@michael.brudna.chmu=
rka.net
i haven't tried that.. i just searched for the HTTP::Cookies::Mozilla
package in ubuntu, but didn't find it, how should i install it? thanks
again.
------------------------------
Date: Mon, 7 Sep 2009 04:44:56 -0700 (PDT)
From: "claus.kick@googlemail.com" <claus.kick@googlemail.com>
Subject: Re: Cookies [Firefox/IE]
Message-Id: <6675694d-19c3-4b6d-aaee-232af1359dc4@w36g2000yqm.googlegroups.com>
On 7 Sep., 01:39, wassup <wassu...@gmail.com> wrote:
> i haven't tried that.. i just searched for the HTTP::Cookies::Mozilla
> package in ubuntu, but didn't find it, how should i install it? thanks
> again.
CPAN Istallation:
1. perl -MCPAN -e shell
a cpan:> shell opens
2. install MOdule::Name
* (i.e.: install DBD::mysql)
------------------------------
Date: 7 Sep 2009 13:53:29 GMT
From: greymausg@mail.com
Subject: Re: Cookies [Firefox/IE]
Message-Id: <slrnhaa425.7es.greymausg@maushome.org>
On 2009-09-07, claus.kick@googlemail.com <claus.kick@googlemail.com> wrote:
> On 7 Sep., 01:39, wassup <wassu...@gmail.com> wrote:
>
>> i haven't tried that.. i just searched for the HTTP::Cookies::Mozilla
>> package in ubuntu, but didn't find it, how should i install it? thanks
>> again.
>
> CPAN Istallation:
>
> 1. perl -MCPAN -e shell
> a cpan:> shell opens
>
> 2. install MOdule::Name
> * (i.e.: install DBD::mysql)
You crooked hacker!.. Let us know how you get on!.
--
Greymaus....
Are You a `human` or a `zombie`?
Case A, vote "No".
------------------------------
Date: Sun, 6 Sep 2009 15:23:04 -0700 (PDT)
From: wassup <wassupme@gmail.com>
Subject: Cookies
Message-Id: <69c3ae2f-fcaf-4978-8e87-640cd6acacf3@r5g2000yqi.googlegroups.com>
hi. is there a way to convert a FF/IE cookie into using it with
mechanize? cuz, i want to login a site that uses recaptcha, and
mechanize can't login that way, so i was thinking of using a cookie
that would make the site think i was already logged in, skiping the
login process.. is this possible? if yes, how can it be done? thanks
in advance!
------------------------------
Date: Sat, 5 Sep 2009 20:07:32 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: copy specific lines
Message-Id: <e4836b9f-e946-4dc9-9b17-69f39fc8a469@v37g2000prg.googlegroups.com>
On Sep 5, 3:23=A0pm, Faith Greenwood <fgno...@gmail.com> wrote:
> Hi,
>
> I am trying to split a file into two parts. My file is as follows:
>
> data
> 1
> 2
> 3
> end data
> data
> 4
> 5
> 6
> end data
>
> I want to split the file into two parts, w/ the first file having the
> following:
> data
> 1
> 2
> 3
> end data
>
> and the second file having:
> data
> 4
> 5
> 6
> end data
>
> I have the following code:
>
> open(SPLITTY, "<", "/media/hd/test.txt");
> my $linecnt=3D0;
> while(<SPLITTY>){
> if(/data/../end data/){
> open(YESSPLIT,">>","/media/hd/testtwo.txt");
> print YESSPLIT $_;
> close YESSPLIT;}
> }
>
> close SPLITTY;
>
> however, this just copies the original file to a new file. How can I
> tweak this to get what I am looking for?
Hm, if you're trying to modify the original file itself,
here's a possibility:
local $^I =3D '.orig';
local @ARGV =3D "/path/to/somefile";
my $half;
while ( <> ) {
if( my $ret =3D /data/../end data/ and not $half ) {
print;
if ( index( $ret, "E0" ) > -1 ) {
$half =3D 'done';
open( my $fh, '>>', ... ) or die $!;
}
} elsif ( /data/../end data/ and $half ) {
print $fh $_;
}
}
--
Charles DeRykus
------------------------------
Date: Sat, 5 Sep 2009 22:14:10 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: copy specific lines
Message-Id: <08e47a40-1795-4223-8c8c-6abcb142bfea@s21g2000prm.googlegroups.com>
On Sep 5, 8:07=A0pm, "C.DeRykus" <dery...@gmail.com> wrote:
> On Sep 5, 3:23=A0pm, Faith Greenwood <fgno...@gmail.com> wrote:
>
>
>
> ...
>
> Hm, if you're trying to modify the original file itself,
> here's a possibility:
>
> =A0 =A0 local $^I =3D '.orig';
> =A0 =A0 local @ARGV =3D =A0"/path/to/somefile";
> =A0 =A0 my $half;
my $fh; # <------
>
> =A0 =A0 while ( <> ) {
> =A0 =A0 =A0 =A0if( my $ret =3D /data/../end data/ and not $half ) {
> =A0 =A0 =A0 =A0 =A0 =A0print;
> =A0 =A0 =A0 =A0 =A0 =A0if =A0( index( $ret, "E0" ) > -1 ) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 $half =3D 'done';
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 open( my $fh, '>>', ... ) or die $!;
open( $fh, '>>', ... ) or die $!; # <------
> =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0} elsif ( /data/../end data/ and $half ) {
> =A0 =A0 =A0 =A0 =A0 =A0print $fh $_;
> =A0 =A0 =A0 =A0}
> =A0 =A0 }
>
--
Charles DeRykus
------------------------------
Date: Sun, 06 Sep 2009 15:48:51 -0700
From: sln@netherlands.com
Subject: Re: copy specific lines
Message-Id: <dmd8a515i34rlik812lv82hh69qrlj5ifg@4ax.com>
On Sat, 5 Sep 2009 15:23:30 -0700 (PDT), Faith Greenwood <fgnowfg@gmail.com> wrote:
>Hi,
>
>I am trying to split a file into two parts. My file is as follows:
>
>data
>1
>2
>3
>end data
>data
>4
>5
>6
>end data
>
>I want to split the file into two parts, w/ the first file having the
>following:
>data
>1
>2
>3
>end data
>
>and the second file having:
>data
>4
>5
>6
>end data
>
>I have the following code:
>
>open(SPLITTY, "<", "/media/hd/test.txt");
>my $linecnt=0;
>while(<SPLITTY>){
>if(/data/../end data/){
>open(YESSPLIT,">>","/media/hd/testtwo.txt");
>print YESSPLIT $_;
>close YESSPLIT;
>}
>}
>close SPLITTY;
>
>however, this just copies the original file to a new file. How can I
>tweak this to get what I am looking for?
This is a way.
However, this is too simple of an example and just
demonstrates the range operator.
Its a little more challenging that the data sets
have identical header-footers.
How would you use the fact that they are identical
(not in data), in the real sense?
Just curious.
-sln
-------------
use strict;
use warnings;
(open my $fh1, ">data1.txt") && (open my $fh2, ">data2.txt")
or die "couldn't open an output file: $!";
my $fh = $fh1;
while(<DATA>) {
if ((/^data/../^end data/) =~ /\d+(E0|)?/) {
print $fh "$_";
$1 and $fh=$fh2;
}
}
close $fh1;
close $fh2;
__DATA__
data
1
2
3
end data
data
4
5
6
end data
------------------------------
Date: Sun, 06 Sep 2009 22:00:05 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 1.2 Who supports Perl? Who develops it? Why is it free?
Message-Id: <FhWom.142049$sC1.138040@newsfe17.iad>
This is an excerpt from the latest version perlfaq1.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
1.2: Who supports Perl? Who develops it? Why is it free?
The original culture of the pre-populist Internet and the deeply-held
beliefs of Perl's author, Larry Wall, gave rise to the free and open
distribution policy of perl. Perl is supported by its users. The core,
the standard Perl library, the optional modules, and the documentation
you're reading now were all written by volunteers. See the personal note
at the end of the README file in the perl source distribution for more
details. See perlhist (new as of 5.005) for Perl's milestone releases.
In particular, the core development team (known as the Perl Porters) are
a rag-tag band of highly altruistic individuals committed to producing
better software for free than you could hope to purchase for money. You
may snoop on pending developments via the archives at
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/ and
http://archive.develooper.com/perl5-porters@perl.org/ or the news
gateway nntp://nntp.perl.org/perl.perl5.porters or its web interface at
http://nntp.perl.org/group/perl.perl5.porters , or read the faq at
http://dev.perl.org/perl5/docs/p5p-faq.html , or you can subscribe to
the mailing list by sending perl5-porters-request@perl.org a
subscription request (an empty message with no subject is fine).
While the GNU project includes Perl in its distributions, there's no
such thing as "GNU Perl". Perl is not produced nor maintained by the
Free Software Foundation. Perl's licensing terms are also more open than
GNU software's tend to be.
You can get commercial support of Perl if you wish, although for most
users the informal support will more than suffice. See the answer to
"Where can I buy a commercial version of perl?" for more information.
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Sun, 06 Sep 2009 10:00:02 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 3.12 Where can I get perl-mode for emacs?
Message-Id: <CKLom.17021$UH2.15685@newsfe01.iad>
This is an excerpt from the latest version perlfaq3.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
3.12: Where can I get perl-mode for emacs?
Since Emacs version 19 patchlevel 22 or so, there have been both a
perl-mode.el and support for the Perl debugger built in. These should
come with the standard Emacs 19 distribution.
In the Perl source directory, you'll find a directory called "emacs",
which contains a cperl-mode that color-codes keywords, provides
context-sensitive help, and other nifty things.
Note that the perl-mode of emacs will have fits with "main'foo" (single
quote), and mess up the indentation and highlighting. You are probably
using "main::foo" in new Perl code anyway, so this shouldn't be an
issue.
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Sun, 06 Sep 2009 03:59:58 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 3.9 Is there a ctags for Perl?
Message-Id: <2tGom.142514$O23.20761@newsfe11.iad>
This is an excerpt from the latest version perlfaq3.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
3.9: Is there a ctags for Perl?
(contributed by brian d foy)
Ctags uses an index to quickly find things in source code, and many
popular editors support ctags for several different languages, including
Perl.
Exuberent ctags supports Perl: http://ctags.sourceforge.net/
You might also try pltags: http://www.mscha.com/pltags.zip
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Mon, 07 Sep 2009 04:00:05 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 4.10 Why aren't my random numbers random?
Message-Id: <9z%om.288918$E61.61998@newsfe09.iad>
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.10: Why aren't my random numbers random?
If you're using a version of Perl before 5.004, you must call "srand"
once at the start of your program to seed the random number generator.
BEGIN { srand() if $] < 5.004 }
5.004 and later automatically call "srand" at the beginning. Don't call
"srand" more than once--you make your numbers less random, rather than
more.
Computers are good at being predictable and bad at being random (despite
appearances caused by bugs in your programs :-). see the random article
in the "Far More Than You Ever Wanted To Know" collection in
http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz , courtesy of Tom Phoenix,
talks more about this. John von Neumann said, "Anyone who attempts to
generate random numbers by deterministic means is, of course, living in
a state of sin."
If you want numbers that are more random than "rand" with "srand"
provides, you should also check out the "Math::TrulyRandom" module from
CPAN. It uses the imperfections in your system's timer to generate
random numbers, but this takes quite a while. If you want a better
pseudorandom generator than comes with your operating system, look at
"Numerical Recipes in C" at http://www.nr.com/ .
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Mon, 07 Sep 2009 10:00:01 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
Message-Id: <BQ4pm.26078$Y83.19327@newsfe21.iad>
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.42: How can I tell whether a certain element is contained in a list or array?
(portions of this answer contributed by Anno Siegel and brian d foy)
Hearing the word "in" is an *in*dication that you probably should have
used a hash, not a list or array, to store your data. Hashes are
designed to answer this question quickly and efficiently. Arrays aren't.
That being said, there are several ways to approach this. In Perl 5.10
and later, you can use the smart match operator to check that an item is
contained in an array or a hash:
use 5.010;
if( $item ~~ @array )
{
say "The array contains $item"
}
if( $item ~~ %hash )
{
say "The hash contains $item"
}
With earlier versions of Perl, you have to do a bit more work. If you
are going to make this query many times over arbitrary string values,
the fastest way is probably to invert the original array and maintain a
hash whose keys are the first array's values:
@blues = qw/azure cerulean teal turquoise lapis-lazuli/;
%is_blue = ();
for (@blues) { $is_blue{$_} = 1 }
Now you can check whether $is_blue{$some_color}. It might have been a
good idea to keep the blues all in a hash in the first place.
If the values are all small integers, you could use a simple indexed
array. This kind of an array will take up less space:
@primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31);
@is_tiny_prime = ();
for (@primes) { $is_tiny_prime[$_] = 1 }
# or simply @istiny_prime[@primes] = (1) x @primes;
Now you check whether $is_tiny_prime[$some_number].
If the values in question are integers instead of strings, you can save
quite a lot of space by using bit strings instead:
@articles = ( 1..10, 150..2000, 2017 );
undef $read;
for (@articles) { vec($read,$_,1) = 1 }
Now check whether "vec($read,$n,1)" is true for some $n.
These methods guarantee fast individual tests but require a
re-organization of the original list or array. They only pay off if you
have to test multiple values against the same array.
If you are testing only once, the standard module "List::Util" exports
the function "first" for this purpose. It works by stopping once it
finds the element. It's written in C for speed, and its Perl equivalent
looks like this subroutine:
sub first (&@) {
my $code = shift;
foreach (@_) {
return $_ if &{$code}();
}
undef;
}
If speed is of little concern, the common idiom uses grep in scalar
context (which returns the number of items that passed its condition) to
traverse the entire list. This does have the benefit of telling you how
many matches it found, though.
my $is_there = grep $_ eq $whatever, @array;
If you want to actually extract the matching elements, simply use grep
in list context.
my @matches = grep $_ eq $whatever, @array;
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Mon, 7 Sep 2009 06:52:54 -0700 (PDT)
From: julia <julia_2683@hotmail.com>
Subject: join lines - perl command
Message-Id: <39e592c2-50de-4146-94f0-1823a492ca5c@o21g2000vbl.googlegroups.com>
What is the perl command to join lines ? I appreciate your help.
linelineline\newline (line1)
lineline\newline (line2)
linelinelineline\newline (line3)
&
rowrowrow\newline (line1)
rowrow\newline(line2)
row\newline(line3)
&
whateverwhatever(line1)
whateverwhatever(line2)
whatever(line3)
Result
linelineline&rowrowrow&whateverwhatever\newline
lineline&rowrow&whateverwhatever\newline
linelinelineline&row&whatever\newline
------------------------------
Date: Mon, 07 Sep 2009 15:31:52 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: join lines - perl command
Message-Id: <2rmdnWebDYTFhDjXnZ2dnUVZ8iFi4p2d@brightview.co.uk>
julia wrote:
> What is the perl command to join lines ? I appreciate your help.
>
> linelineline\newline (line1)
> lineline\newline (line2)
> linelinelineline\newline (line3)
> &
> rowrowrow\newline (line1)
> rowrow\newline(line2)
> row\newline(line3)
> &
> whateverwhatever(line1)
> whateverwhatever(line2)
> whatever(line3)
>
> Result
> linelineline&rowrowrow&whateverwhatever\newline
> lineline&rowrow&whateverwhatever\newline
> linelinelineline&row&whatever\newline
Dunno about perl, but paste(1) on *nix does it
BugBear
------------------------------
Date: Mon, 07 Sep 2009 10:00:40 -0500
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: join lines - perl command
Message-Id: <IIadnfPYOKaFvTjXnZ2dnUVZ_uednZ2d@posted.hiwaay2>
julia <julia_2683@hotmail.com> wrote
: What is the perl command to join lines ? I appreciate your help.
:
: linelineline\newline (line1)
: lineline\newline (line2)
: linelinelineline\newline (line3)
: &
: rowrowrow\newline (line1)
: rowrow\newline(line2)
: row\newline(line3)
: &
: whateverwhatever(line1)
: whateverwhatever(line2)
: whatever(line3)
:
: Result
: linelineline&rowrowrow&whateverwhatever\newline
: lineline&rowrow&whateverwhatever\newline
: linelinelineline&row&whatever\newline
Looks like you want to swap rows with columns of (i.e., transpose)
your input and then join the values in the output:
$ cat try
#! /usr/bin/perl
use warnings;
use strict;
# see http://bit.ly/DataListTranspose
sub transpose {
return unless @_;
my $head = shift;
if (!@$head) {
&transpose; # reuse @_
}
else {
unshift @_ => $head;
( [ map $_->[0] => @_ ]
, transpose(map { shift @$_; $_ } @_)
);
}
}
$/ = "";
my @lines;
while (<DATA>) {
push @lines => [ split /\n+/ ]
}
$" = "&";
foreach my $row (transpose @lines) {
print "@$row\n";
}
__DATA__
linelineline
lineline
linelinelineline
rowrowrow
rowrow
row
whateverwhatever
whateverwhatever
whatever
$ ./try
linelineline&rowrowrow&whateverwhatever
lineline&rowrow&whateverwhatever
linelinelineline&row&whatever
Perl's special $" (described in the perlvar documentation) allows
you to specify your own separator when interpolating arrays into
strings. The above print is equivalent to
print join("&" => @$row), "\n";
The first recursive call to transpose looks odd but is using the
following feature:
Subroutines may be called recursively. If a
subroutine is called using the "&" form, the argument
list is optional, and if omitted, no @_ array is set
up for the subroutine: the @_ array at the time of the
call is visible to subroutine instead.
See the perlsub documentation.
Hope this helps,
Greg
--
Of course, postmodernism has taught us that there is no objective reality
and that we all forge our own interpretations, usually with long words and
often in French, about what reality we perceive. So I don't want to color
your interpretation. Except to say that it's wrong. :-) -- Jon Orwant
------------------------------
Date: Mon, 7 Sep 2009 07:50:59 -0700 (PDT)
From: phaedrus <orion.osiris@virgin.net>
Subject: Query about viewing web pages.
Message-Id: <8f4b90a5-6000-496e-9e7a-92a232afc5a5@s31g2000yqs.googlegroups.com>
Hi guys,
I have a problem with online newspaper pages that contain long
paragraphs of nested comments.
Whenever I post a comment, the page reloads with new comments people
have submitted since I last did a refresh or a post. Now however, as
well as a bunch of new comments, I still have all the old ones some of
which i've read and some not. But these are hard to distinguish.Very
often, I'm half way through an item before I recall I've read it
before. And of course, the longer and more complex the page becomes,
the worse the problem.
I need some way of 'graying out' the already-red comments, so the
unread ones can stand out and I can spot them easily. I don't want the
pre-existing comments erased completely since some of the new ones may
refer back to them.
I haven't seen a browser that supports this feature so I'm going to
have to tackle it by writing a C program but someone on another group
said I should consider Perl first as it's far more suitable. Any
suggestions as to the best way to approach this task? Thanks!
------------------------------
Date: Sun, 6 Sep 2009 06:50:37 -0700 (PDT)
From: rlf <rlfoster2424@gmail.com>
Subject: Re: Why does "$v = @ARGV[0]" work ?
Message-Id: <9752b967-d071-44bb-9057-132551738a4e@g23g2000yqh.googlegroups.com>
On 5 Sep, 10:42, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Don Piven <spamt...@piven.net>:
>
> > rlf wrote:
> > > I've taken over some perl code that starts out with :
>
> > > $v =3D @ARGV[0]
>
> > > That's an @ sign on ARGV, not a dollar sign.
>
> > > This seems to get the first element OK, but I don' know why. I've
> > > never seen this construct used before, and I cannot find a parser rul=
e
> > > that says that you could use EITHER a $ or @ in this context.
>
> It's worth noting that 'use warnings' will warn about this. If you have
> inherited some code with dodgy coding standards, my recommendation would
> be to start by adding
>
> =A0 =A0 use strict;
> =A0 =A0 use warnings;
>
> at the top and fixing all the resultant diagnostics.
>
> <snip>
>
>
>
> > @ARGV[0] is a one-element slice out of the @ARGV array, which is then
> > used as a list constructor for the assignment. =A0Now, man perldata say=
s
> > that "[in] a context not requiring a list value, the value of what
> > appears to be a list literal is simply the value of the final element",
> > working the same as C's and Perl's comma operator. =A0More generally,
> > evaluating a list constructor in scalar context yields you that
> > last-element behavior, while evaluating a list VARIABLE
>
> An array. The difference between list and array is important.
>
> > in scalar
> > context gets you the length of the list.
>
> Ben
Thank you all for the clarification.
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 2586
***************************************