[17760] in Perl-Users-Digest
Perl-Users Digest, Issue: 5180 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 22 11:10:30 2000
Date: Fri, 22 Dec 2000 08:10:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977501414-v9-i5180@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 22 Dec 2000 Volume: 9 Number: 5180
Today's topics:
Re: regular expr. <gordonrogers@my-deja.com>
Re: regular expr. <snefsite@hotmail.com>
Re: regular expr. <somewhere@planet.earth>
Re: regular expr. <snefsite@hotmail.com>
Re: Reverse "append to file" (Brian Pontz)
Re: Reverse "append to file" <joe+usenet@sunstarsys.com>
Re: Reverse "append to file" (Abigail)
Re: Reverse "append to file" (Tad McClellan)
Re: Site Up Status <ubl@schaffhausen.de>
Re: Sorting hash eggrock@my-deja.com
Re: Understanding interpolation <bart.lateur@skynet.be>
web ask seting cookie when perl ... justinlee1998@my-deja.com
Re: what is perldoc? <johngros@Spam.bigpond.net.au>
Re: Why are multiple zeroes true? (Abigail)
Re: Why are multiple zeroes true? <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 22 Dec 2000 12:23:03 GMT
From: GordonR <gordonrogers@my-deja.com>
Subject: Re: regular expr.
Message-Id: <91vh35$2v6$1@nnrp1.deja.com>
> When using regexes the best way to do it is to say what you mean. Yor
regex
> will probably look like this:
>
> $string="some text here [BLA=qwert-foo] and something else here";
> $string=~m/BLA=(.*)/; # match 'BLA=' first and then everything
else
> (.*)
>
> $what_I_want=$1;
I would suggest that the regex should be m/BLA=(.*)]/ as I doubt if you
are interested in the closing ']'.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 22 Dec 2000 13:35:07 +0100
From: "Sven Franke" <snefsite@hotmail.com>
Subject: Re: regular expr.
Message-Id: <91vhjf$ore$1@enterprise.cistron.net>
"Michael Schlueter" <Michael.Schlueter@philips.com> schreef in bericht
news:3a433295$0$8781$4dbef881@businessnews.de.uu.net...
> Sven,
>
> A way to do it 'without' regexes may be:
>
> $string="some text here [BLA=qwert-foo] and something else here";
> @list=split/BLA=/, $string;
>
<CUT>
> When using regexes the best way to do it is to say what you mean. Yor
regex
> will probably look like this:
>
> $string="some text here [BLA=qwert-foo] and something else here";
> $string=~m/BLA=(.*)/; # match 'BLA=' first and then everything else
>
> $what_I_want=$1;
>
<CUT>
>
> Hope this helps you,
> Michael
>
>
Well, I used this one:
$string = 'Blablablablabla[TITLE=Books in
heaven]FooFOOfoo[BLA=*qwe/qwer/qwerty\a]qwertyqwerty[FOO]';
$string = m/\[TITLE=(.*)\]/;
But now $1 contains : "Books in
heaven]FooFOOfoo[BLA=*qwe/qwer/qwerty\a]qwertyqwerty[FOO]".
I only want the text "Books in heaven"
How can I achieve this?
(what I really want is this:
I need the text:
Books in heaven
qwe (text between *.../
a (text between \.] )
Sven
------------------------------
Date: Fri, 22 Dec 2000 14:32:53 +0100
From: "Dimitri Gunsing" <somewhere@planet.earth>
Subject: Re: regular expr.
Message-Id: <91vl5e$phv$1@list.pbnec.nl>
>
> Well, I used this one:
>
> $string = 'Blablablablabla[TITLE=Books in
> heaven]FooFOOfoo[BLA=*qwe/qwer/qwerty\a]qwertyqwerty[FOO]';
> $string = m/\[TITLE=(.*)\]/;
>
> But now $1 contains : "Books in
> heaven]FooFOOfoo[BLA=*qwe/qwer/qwerty\a]qwertyqwerty[FOO]".
> I only want the text "Books in heaven"
>
> How can I achieve this?
> (what I really want is this:
> I need the text:
> Books in heaven
> qwe (text between *.../
> a (text between \.] )
>
> Sven
>
Use this one :
$string =~ m/\[TITLE=(.*?)\]/;
The ? means it should save the text until the next atom in the expression
which is the closing ].
Dimitri
------------------------------
Date: Fri, 22 Dec 2000 14:45:40 +0100
From: "Sven Franke" <snefsite@hotmail.com>
Subject: Re: regular expr.
Message-Id: <91vlnq$u0b$1@enterprise.cistron.net>
Thanx!
"Dimitri Gunsing" <somewhere@planet.earth> schreef in bericht
news:91vl5e$phv$1@list.pbnec.nl...
------------------------------
Date: Fri, 22 Dec 2000 14:11:07 GMT
From: pontz@NO_SPAM.channel1.com (Brian Pontz)
Subject: Re: Reverse "append to file"
Message-Id: <3a435ed6.43289935@news.ne.mediaone.net>
>I'm all new to Perl and want to write a guestbook. (Heard that before?
>;) What my problem is is how to write to the beginning of a file, and
>letting the previous contents "move down" in the file.
Most I've seen append to the end of the file and read the file
backwards.
Use Uri's File::ReadBackwards module. You can download it at
http://www.cpan.org/authors/id/U/UR/URI/File-ReadBackwards-0.94.tar.gz
Or try this function but remember the module is the fastest.
sub Tail {
my ($file,$count) = @_;
my (@lines);
open(TFILE,"<$file") || die "Couldnt open $file: $!\n";
seek(TFILE,0,2); # start at end, read backwards
while (($#lines < $count)&(seek(TFILE,-1,1)||push(@lines,$line))) {
read(TFILE,$buffer,1);
seek(TFILE,-1,1);
if ( $buffer =~ /\n/ ) {
push(@lines,$line); $line="\n";
} else {
$line="$buffer$line";
}
}
close(TFILE);
return @lines;
}
Brian Pontz
comp.lang.perl.misc Searchable Archive
http://www.axehind.com/complangperl.html
------------------------------
Date: 22 Dec 2000 09:13:07 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Reverse "append to file"
Message-Id: <m3d7ekh7d8.fsf@mumonkan.sunstarsys.com>
chr1st1an <cyner.mail@sweden.com> writes:
> What my problem is is how to write to the beginning of a file, and
> letting the previous contents "move down" in the file.
[...]
> Suggestions? Please?
>
> (I did check your and other's FAQs before submitting this question.
> Couldn't find it, but that may be due to my lack of Perl knowledge.)
% man perldoc
% perldoc -q insert
--
Joe Schaefer
------------------------------
Date: 22 Dec 2000 14:55:03 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Reverse "append to file"
Message-Id: <slrn946qq7.95k.abigail@tsathoggua.rlyeh.net>
chr1st1an (cyner.mail@sweden.com) wrote on MMDCLXX September MCMXCIII in
<URL:news:3A431DBC.1000505@sweden.com>:
~~
~~ (I did check your and other's FAQs before submitting this question.
~~ Couldn't find it, but that may be due to my lack of Perl knowledge.)
I could explain it, but if your knowledge is such that you couldn't spot
the appropriate question in the FAQ, there's no point in explaining it
to you.
Abigail
--
BEGIN {$^H {q} = sub {$_ [1] =~ y/S-ZA-IK-O/q-tc-fe-m/d; $_ [1]}; $^H = 0x28100}
print "Just another PYTHON hacker\n";
------------------------------
Date: Fri, 22 Dec 2000 09:32:44 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reverse "append to file"
Message-Id: <slrn946pgc.7ga.tadmc@magna.metronet.com>
chr1st1an <cyner.mail@sweden.com> wrote:
>Subject: Reverse "append to file"
^^^^^^
^^^^^^ a search term
>I'm all new to Perl and want to write a guestbook. (Heard that before?
>;) What my problem is is how to write to the beginning of a file
>Suggestions? Please?
>
>(I did check your and other's FAQs before submitting this question.
>Couldn't find it, but that may be due to my lack of Perl knowledge.)
perldoc -q append
"How do I change one line in a file/
delete a line in a file/
insert a line in the middle of a file/
append to the beginning of a file?"
You can modify the code given there for your situation by print()ing
to NEW before you start copying from OLD.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 22 Dec 2000 15:31:42 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Site Up Status
Message-Id: <3A4365CF.35F7B1E5@schaffhausen.de>
robertf57@my-deja.com schrieb:
>
> Can anyone recommend a publicly available Perl script that will monitor
> a website's (up) status and page the admin if it goes down? Thanks.
No, but cgi-resources.com is a good place to look.
->malte
------------------------------
Date: Fri, 22 Dec 2000 15:08:25 GMT
From: eggrock@my-deja.com
Subject: Re: Sorting hash
Message-Id: <91vqp5$a6b$1@nnrp1.deja.com>
> You should instead do it as in the FAQ.
And the FAQ says:
Here we'll do a reverse numeric sort by value, and if two keys are
identical, sort by length of key, and if that fails, by straight ASCII
comparison of the keys (well,
possibly modified by your locale -- see the perllocale manpage).
@keys = sort {
$hash{$b} <=> $hash{$a}
||
length($b) <=> length($a)
||
$a cmp $b
} keys %hash;
With no explanation other than this.
This is too terse, IMHO.
Read the description of 'sort' in the Programming Perl book (2nd ed.
anyways) which goes into a bit more depth about how this works (not you
Tad, god knows you probably have it memorized. ;-)
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 22 Dec 2000 11:24:02 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Understanding interpolation
Message-Id: <lud64tkea10sqdvangskvac8jtqs8efqs3@4ax.com>
The WebDragon wrote:
>sorta but not quite.. what if I wanted something like this:
>
>line 0 -> orange
>line 1 -> orange
>line 2 -> red
>line 3 -> red
>line 4 -> orange
>line 5 -> orange
>line 6 -> red
>line 7 -> red
Do integer divide by group size. Er... in Perl, that is divide, and take
int() of the result. Then, take modulo colors. Here, both numbers are 2;
and 3 in your other example.
Here's an example with 3 colors and groupsize of 2:
@color = qw(orange none green);
my $grouped = 2;
for(my $i = 0; $i < 3 * $grouped * @color; $i++) {
print "Line @{[$i+1]}: $color[int($i/$grouped)%@color]\n";
}
Note that for the arithmetic, my first line is number 0; for printout,
it's 1.
--
Bart.
------------------------------
Date: Fri, 22 Dec 2000 13:31:01 GMT
From: justinlee1998@my-deja.com
Subject: web ask seting cookie when perl ...
Message-Id: <91vl2m$5t6$1@nnrp1.deja.com>
I want to use perl script to login a web server,
but the web server ask to cookie.
I don't know how to process.
Any suggest will be appreciate
Justin
--------------------
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$pubStr='http://china.alibaba.com/bin/express/express?cd=0';
&httpPublish($pubStr);
#this step will pass
#next step , web server will say, it need cookie
my $req = POST 'http://china.alibaba.com/bin/user/signin',
[ UserId => 'name', cc => '1', step => '2',
Done => '/bin/express/express?cd=0',
Password => 'vvvvvv'
];
print $ua->request($req)->as_string;
sub httpPublish
{
use LWP::UserAgent;
my($httpStr)=@_;
$ua = new LWP::UserAgent;
$ua->agent("$0/0.1 " . $ua->agent);
$req = new HTTP::Request 'GET' => $httpStr;
$req->header('Accept' => 'text/html');
# send request
$res = $ua->request($req);
# check the outcome
if ($res->is_success) {
# print $res->content;
print "success";
} else {
print "Error: " . $res->status_line . "\n";
}
}
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 22 Dec 2000 13:10:59 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: what is perldoc?
Message-Id: <DpI06.29209$xW4.226035@news-server.bigpond.net.au>
"Helgi Briem" <helgi@NOSPAMdecode.is> wrote in message
news:3a408227.1118886273@news.itn.is...
> On Tue, 19 Dec 2000 17:43:46 GMT, alazarev1981@my-deja.com
> perldoc -X Module # info on Module
I have been looking for how to get info on specific modules.
It does pay to read almost everything ;-)
------------------------------
Date: 22 Dec 2000 13:41:28 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Why are multiple zeroes true?
Message-Id: <slrn946mg8.95k.abigail@tsathoggua.rlyeh.net>
Tom Christiansen (tchrist@perl.com) wrote on MMDCLXX September MCMXCIII
in <URL:news:3a42b4e3@cs.colorado.edu>:
{} In article <91ubat$7kb$1@nnrp1.deja.com>, <miko@idocs.com> wrote:
{} >Well, that's exactly the reason that led to me expect "000" to be false:
{} >it fits into the first rule of reducing to zero (as it does in a numeric
{} >context). To make "0" false but "000" true you have use more
{} >complicated rules.
{} >
{} >But obviously, my original question has been answered: the existing
{} >rules are obviously What Everyone Else Expects, so they're the best
{} >rules.
{}
{} I'm not so sure that that logic is wholly unimpeachable. I also don't
{} think it happens to be the case.
{}
{} In fact, I during the perl6 ruminations asked whether we didn't
{} want to seriously rethink this matter. I'm not sure whether it
{} made an RFC or not. I think that It was in my "PERL6STORM" thread,
{} where I wrote:
{}
{} =item perl6storm #0052
{}
{} Make "0" (more?) true so that people don't get surprised.
{}
{} or
{}
{} Make "0.00" (more?) false so that people don't get surprised.
Too bad Perl doesn't have a separate context "boolean" next to scalar
context and list context. Having 0 (and '' and undef) be "false" and
other values true is a hack, and nothing more. Convenient for a minimal
language like C, but a shame for a language like Perl.
Don't let the fact that in many cases 0/''/undef being false works out
well give you the impression it can't be done better.
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
------------------------------
Date: Fri, 22 Dec 2000 14:52:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why are multiple zeroes true?
Message-Id: <jhq64to4q0d9da44d86o9map1c95crs9hc@4ax.com>
Abigail wrote:
>:} you are going backwards. starting with undef you can get to '', 0 and
>:} then to '0'. you cannot generate '00' from those with just context.
>
>You can't generate 0.0 from context either, yet that's false too.
Not so. "0.0" as a string is true, and 0.0 as a number is identical to
0.
$\ ="\n";
print "'0.0' is ".('0.0'?"true":"false");
print 0.0;
-->
'0.0' is true
0
--
Bart.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 5180
**************************************