[17392] in Perl-Users-Digest
Perl-Users Digest, Issue: 4814 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 5 11:10:26 2000
Date: Sun, 5 Nov 2000 08:10:11 -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: <973440611-v9-i4814@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 5 Nov 2000 Volume: 9 Number: 4814
Today's topics:
Redirection script not handling "?" (Alan Page)
Re: Redirection script not handling "?" <mailme@shadownet.net>
Re: Redirection script not handling "?" (Alan Page)
Split and clean data? <vivekvp@spliced.com>
Re: Split and clean data? (Mark-Jason Dominus)
Re: Unix commands via perl? <elaine@chaos.wustl.edu>
What i'm i doing wrong help!! <markscott@barclays.net>
Re: What i'm i doing wrong help!! (Gwyn Judd)
Re: Why would subs not get the right args? <usenet@hank.org>
Re: Why would subs not get the right args? <bart.lateur@skynet.be>
Re: Why would subs not get the right args? <bart.lateur@skynet.be>
Re: Why would subs not get the right args? (Martien Verbruggen)
Re: Why would subs not get the right args? <usenet@hank.org>
Re: XML::Parser and diacriticals <ck@ix.heise.de>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 05 Nov 2000 07:10:09 GMT
From: alandpage@aol.comnospam (Alan Page)
Subject: Redirection script not handling "?"
Message-Id: <20001105021009.04482.00000214@ng-fi1.aol.com>
Hello,
I am trying to set up a redirection script on my site so that when people leave
my site via a link, I will be able to track the fact that they clicked on the
link (e.g.: the
link will be href="cgi-bin/redir.cgi?http://www.foo.com/").
The script that I downloaded works for vanilla URLs, but when I feed it a URL
with a question mark in it, it only returns the error text, saying that my URL
should start with http or ftp. I haven't been able to decode the regular
expression statements to figure out what's going on. Any ideas? Here's the
script:
$Query_File = $ENV{QUERY_STRING};
$Query_File =~ s/%([0-9A-F][0-9A-F])/pack("C",oct("0x$1"))/ge;
$Query_File =~ tr/+/ /;
($url) = split(/\&/,$Query_File);
if ($url =~ /=/) {
($name, $url) = split(/=/, $url);
}
if ($url =~ /^(ht|f)tp:\/\//) {
print "Location: $url\n\n";
} else {
&Error("Your URL sould be begining by http:// or ftp://\n");
}
Thank you in advance,
Alan Page
Sandy Hook, CT USA
------------------------------
Date: Sun, 5 Nov 2000 10:49:33 +0100
From: "[AGUT] Shadow Code" <mailme@shadownet.net>
Subject: Re: Redirection script not handling "?"
Message-Id: <8u3aem$27s$1@porthos.nl.uu.net>
Hmmm, try translating the seccond ? to \?\ or a hex code..
(more on hex codes: see www.cgi101.com/class)
Shadow
--
-----------------------------------------------------
Sig, snip it, if you want
-----------------------------------------------------
Wanna have free money?
Without surfer?
Or just wanna help me?
Go, join, and use this:
http://connect.to/yourfreemoney
Thx, I owe you one!
-----------------------------------------------------
"Alan Page" <alandpage@aol.comnospam> schreef in bericht
news:20001105021009.04482.00000214@ng-fi1.aol.com...
> Hello,
>
> I am trying to set up a redirection script on my site so that when people
leave
> my site via a link, I will be able to track the fact that they clicked on
the
> link (e.g.: the
> link will be href="cgi-bin/redir.cgi?http://www.foo.com/").
>
> The script that I downloaded works for vanilla URLs, but when I feed it a
URL
> with a question mark in it, it only returns the error text, saying that my
URL
> should start with http or ftp. I haven't been able to decode the regular
> expression statements to figure out what's going on. Any ideas? Here's the
> script:
>
>
> $Query_File = $ENV{QUERY_STRING};
> $Query_File =~ s/%([0-9A-F][0-9A-F])/pack("C",oct("0x$1"))/ge;
> $Query_File =~ tr/+/ /;
> ($url) = split(/\&/,$Query_File);
>
> if ($url =~ /=/) {
> ($name, $url) = split(/=/, $url);
> }
>
> if ($url =~ /^(ht|f)tp:\/\//) {
> print "Location: $url\n\n";
> } else {
> &Error("Your URL sould be begining by http:// or ftp://\n");
> }
>
> Thank you in advance,
> Alan Page
> Sandy Hook, CT USA
------------------------------
Date: 05 Nov 2000 14:32:00 GMT
From: alandpage@aol.comnospam (Alan Page)
Subject: Re: Redirection script not handling "?"
Message-Id: <20001105093200.10025.00001378@ng-ch1.aol.com>
>Hmmm, try translating the seccond ? to \?\ or a hex code..
Would that be on the HTML form, in the link?
>(more on hex codes: see www.cgi101.com/class)
Great! The regular expression that's tripping me up is explained right there!
>
>Shadow
Thanks for the help,
Alan
------------------------------
Date: Sun, 05 Nov 2000 13:44:18 GMT
From: vivekvp <vivekvp@spliced.com>
Subject: Split and clean data?
Message-Id: <8u3o7i$7cr$1@nnrp1.deja.com>
Hello,
I have data in the format of:
1|Name|Phone|screwed up formatted data|screwed up formatted
data|spouse|address|date|open|
The problem is the screwed up fields have multiple lines - but each line
is appearing as a separate line.
I am trying to load this data into a database - but the 2 'screwed up'
fields have odd characters in them. How do I strip out all characters
except text and number from those 2 fields? That inludes tabs, line
feeds etx?
Any help?
Thanks you!
V
--
He who fights and runs away, lives to run another day!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 05 Nov 2000 14:12:08 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Split and clean data?
Message-Id: <3a056ab7.6aaa$184@news.op.net>
Keywords: eyebright, hurl, property, sweet
[mailed and posted]
In article <8u3o7i$7cr$1@nnrp1.deja.com>, vivekvp <vivekvp@spliced.com> wrote:
>I have data in the format of:
>
>1|Name|Phone|screwed up formatted data|screwed up formatted
>data|spouse|address|date|open|
>
>
>The problem is the screwed up fields have multiple lines - but each line
>is appearing as a separate line.
The best thing to do is to re-assemble the broken lines into whole
records. Since you know that each whole record will have exactly 9
fields, this is easy to do. Use something like this:
while (<LINE>) { # read a line
$record .= $_; # append it to the current record
my @fields = split /\|/, $record; # split record into fields
if (@fields == 9) { # this was a complete record
# do something useful with the @fields
$record = ''; # the next line will start a new record
} elsif (@fields > 9) { # Something is wrong
warning "Too much data near line $.; skipping.\n";
$record = '';
} else { # $record is incomplete
# do nothing
}
}
# end of the file, we still have unprocessed data
if ($record ne '') {
warn "WARNING: Incomplete record (`$record') at end of file!\n";
}
Suppose a line contains only the first half of a partial record.
Then $record will be incomplete, and when you do split() on it, you'll
end up with fewer than 9 fields. In that case, you do nothing. The
program goes back to the top of the while loop and reads another
line. Then it appends the second line onto the end of the incomplete
record and tries again to split it. It keeps doing this until it
assembles all the lines that make up the record.
The 'elsif (@fields > 9)' is there just in case some record is
formatted incorrectly, to prevent the program from eating up the whole
rest of the file. But if the data is as you say, this case should
never be exercised.
>I am trying to load this data into a database - but the 2 'screwed up'
>fields have odd characters in them. How do I strip out all characters
>except text and number from those 2 fields? That inludes tabs, line
>feeds etx?
After you have assembled the records and split them into fields, use
$fields[3] =~ tr/A-Za-z0-9//cd;
$fields[4] =~ tr/A-Za-z0-9//cd;
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Sun, 05 Nov 2000 04:51:20 GMT
From: Elaine Ashton <elaine@chaos.wustl.edu>
Subject: Re: Unix commands via perl?
Message-Id: <B62A517B.8E93%elaine@chaos.wustl.edu>
in article slrn90821t.h71.tjla@thislove.dyndns.org, Gwyn Judd at
tjla@guvfybir.qlaqaf.bet quoth:
>>> How many licks does it take to get to the center of a tootsie pop?
>>
>> Doesn't the centre keep moving as you lick so you never actually get there?
>
> On behalf of all the mystified non-merkins: What's a tootsie-pop?
The reference Tom makes is to a brilliant commercial from the 70s that
became a popular culture meme. The cheeky could have answered '3' or 'The
world may never know'.
Of course, this being the age of the internet, someone has put this
commercial up at http://www.commercial-archive.com/data/t/tootsieroll00.html
for posterity and for all the deprived cultures of the world lacking in
tootsie pops :)
e.
------------------------------
Date: Sun, 5 Nov 2000 02:15:41 -0000
From: "mark" <markscott@barclays.net>
Subject: What i'm i doing wrong help!!
Message-Id: <3a04c648$1@news.jakinternet.co.uk>
Hi and thanks for any help in advance, mark.
Okay ive been working really hard, alot of hours and getting nowhere,
All I want to do is log an ip and time stamp it, send it to a file that I
can look
at later, without a visitor knowing the ip has just been recorded.
The Following script works on my machine (Except for the IP) but when I put
it up nothing!!
So I have the following files in Question.
1/logip.html #this is my test page which should execute perl script (default
chmod)
2/ip.pl #The perl script to send the info to ip.html (chmod 755)
3/ip.html # The results? (chmod 646)
<logip.html> looks like this.
---------------------------------------------------------------
<html>
<head>
<title>Log IP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<!#exec cgi="/cgi-bin/ip.pl">
<body bgcolor="#000000">
</body>
</html>
----------------------------------------------------------------------
<ip.pl>
#!/usr/bin/perl
$out="/newweb/ip.html";
open OUT, ">>$out" or die "Cannot open $out for write :$!";
print OUT ": ",scalar(localtime)," IP: ",$ENV{'REMOTE_ADDR'},"\n";
close OUT;
----------------------------------------------------------------------
<ip.html>
"Should have time and ip information"?
My ISP says "Yes, we support SSI, but not executable SSI scripts."
They support Perl
What can be the problem?
Can't thank you enough if you can get me out of this hole i'm in!!
------------------------------
Date: Sun, 05 Nov 2000 09:58:50 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: What i'm i doing wrong help!!
Message-Id: <slrn90ac1s.30b.tjla@thislove.dyndns.org>
I was shocked! How could mark <markscott@barclays.net>
say such a terrible thing:
>Hi and thanks for any help in advance, mark.
>
>Okay ive been working really hard, alot of hours and getting nowhere,
>
>All I want to do is log an ip and time stamp it, send it to a file that I
>can look
>at later, without a visitor knowing the ip has just been recorded.
>My ISP says "Yes, we support SSI, but not executable SSI scripts."
I think you are in the wrong group. Try:
comp.infosystems.www.authoring.cgi
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Never trust a child farther than you can throw it.
------------------------------
Date: Sat, 4 Nov 2000 22:47:41 -0800
From: Bill Moseley <usenet@hank.org>
Subject: Re: Why would subs not get the right args?
Message-Id: <MPG.146ea26a4e7aa52298970b@news.newsguy.com>
On Sat, 04 Nov 2000 17:22:35 -0800 Jeff Zucker (jeff@vpservices.com)
remarked...
> > my $ckmon = @_;
> > this prints '1', when it should print 'jan'. What the heck is going on?
>
> Nope, it should print '1'. The symbol @_ is a list of items passed into
> the sub. The scalar value $ckmon is therefore equal to the length of
> that list, i.e. 1. If you want $ckmon to contain 'jan' you need to do
> one of these:
>
> my $ckmon = shift;
> my $ckmon = $_[0];
> my($ckmon)= @_;
I know TMTOWTDI, but that last one always makes me squirm a bit when I
see it. But that's just me. And I saw it quite a few times today.
When I see it in scripts I tend to deduct points.
--
Bill Moseley
------------------------------
Date: Sun, 05 Nov 2000 10:11:26 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why would subs not get the right args?
Message-Id: <igca0tc3lsvkr8bf4093funhn0omm7i1t5@4ax.com>
Bill Moseley wrote:
>On Sat, 04 Nov 2000 17:22:35 -0800 Jeff Zucker (jeff@vpservices.com)
>remarked...
>> > my $ckmon = @_;
>> > this prints '1', when it should print 'jan'. What the heck is going on?
>>
>> Nope, it should print '1'. The symbol @_ is a list of items passed into
>> the sub.
Not a list, but an array.
>> my $ckmon = shift;
>> my $ckmon = $_[0];
>> my($ckmon)= @_;
>
>I know TMTOWTDI, but that last one always makes me squirm a bit when I
>see it. But that's just me. And I saw it quite a few times today.
>When I see it in scripts I tend to deduct points.
I don't. I use it. It makes converting code when you need one more
parameter for your sub, very easy.
my($ckmon, $opt) = @_;
Now try this with the other two.
--
Bart.
------------------------------
Date: Sun, 05 Nov 2000 10:55:00 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why would subs not get the right args?
Message-Id: <02fa0t4emht9ekakrjbnt0kvro2pdfkcfc@4ax.com>
José Isaías Cabrera wrote:
>I've tried this on an NT and W2000. The script is pretty long and I am
>reading 1.5 Meg of text into an array, but that should not make the
>subroutines go crazy. Or should it?
Er... no necessarily. But A: do you really need to do that, or can you
process the data line by line? And B: don't make copies of that data if
you can avoid it. For example:
@array = <>; # 1.5Mb
test(@array);
sub test {
my @copy = @_; # this makes a COPY of all data!
}
--
Bart.
------------------------------
Date: Sun, 5 Nov 2000 22:27:22 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Why would subs not get the right args?
Message-Id: <slrn90ah0q.53n.mgjv@martien.heliotrope.home>
On Sat, 4 Nov 2000 22:47:41 -0800,
Bill Moseley <usenet@hank.org> wrote:
> On Sat, 04 Nov 2000 17:22:35 -0800 Jeff Zucker (jeff@vpservices.com)
> remarked...
> > > my $ckmon = @_;
> > > this prints '1', when it should print 'jan'. What the heck is going on?
> >
> > Nope, it should print '1'. The symbol @_ is a list of items passed into
> > the sub. The scalar value $ckmon is therefore equal to the length of
> > that list, i.e. 1. If you want $ckmon to contain 'jan' you need to do
> > one of these:
> >
> > my $ckmon = shift;
> > my $ckmon = $_[0];
> > my($ckmon)= @_;
>
> I know TMTOWTDI, but that last one always makes me squirm a bit when I
> see it. But that's just me. And I saw it quite a few times today.
> When I see it in scripts I tend to deduct points.
I don't. I use it when it's most appropriate. Sometimes it just makes
more sense.
sub add_rectangle
{
my $self = shift;
my $rect = shift;
my ($x, $y) = @_;
#Code
}
$square = new Rectangle(40, 40);
$canvas->add_rectangle($square, 30, 45);
sub set_time
{
my $self = shift;
my ($hours, $minutes) = @_;
#Code
}
$clock->set_time(12, 45);
I usually use shift for arguments that really stand on their own, but a
simple assignment for all the other ones. However, it's not a rule. I do
whatever feels most natural.
I've even done things like
sub foo
{
my ($x1, $y1) = splice @_, 0, 2;
my ($x2, $y2) = splice @_, 0, 2;
my $angle = shift;
my %modifiers = @_;
#Done
}
Although this isn't really an interface I used. But I have used splice
in places where pairs or triplets of arguments made sense. I've done
this for coordinates, but also for RGB triplets.
Again, whatever feels most natural at the moment is fine. For me it was
more important to express that the first and second pair of arguments
belonged together than anything else.
Of course, there are other ways of doing these things, other interfaces
that could have been followed. But whatever is chosen, Perl allows one
to process arguments the way that fits the problem at hand best.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | What's another word for Thesaurus?
NSW, Australia |
------------------------------
Date: Sun, 5 Nov 2000 06:40:41 -0800
From: Bill Moseley <usenet@hank.org>
Subject: Re: Why would subs not get the right args?
Message-Id: <MPG.146f112e2704534798970f@news.newsguy.com>
On Sun, 5 Nov 2000 22:27:22 +1100 Martien Verbruggen
(mgjv@tradingpost.com.au) remarked...
> On Sat, 4 Nov 2000 22:47:41 -0800,
> Bill Moseley <usenet@hank.org> wrote:
> > > my $ckmon = shift;
> > > my $ckmon = $_[0];
> > > my($ckmon)= @_;
> >
> > I know TMTOWTDI, but that last one always makes me squirm a bit when I
> > see it. But that's just me. And I saw it quite a few times today.
> > When I see it in scripts I tend to deduct points.
>
> I don't. I use it when it's most appropriate. Sometimes it just makes
> more sense.
I agree with everything you said. I use:
my $foo = shift;
And
my ($foo, $bar) = @_;
and I also often don't grab the parameters until late in the sub, or
just use shift in places.
I guess why my ($foo) = @_ makes me squirm is exactly what started this
thread: my ($foo) = @_ seems to get translated into my $foo = @_
sometimes for new programmers. Oh well. It won't be their only
mistake.
I'm sure everyone has those style issues that makes other code look
weird.
--
Bill Moseley
------------------------------
Date: Sun, 05 Nov 2000 12:30:17 +0100
From: Christian Kirsch <ck@ix.heise.de>
Subject: Re: XML::Parser and diacriticals
Message-Id: <3A0544C9.840C3B95@ix.heise.de>
Bart Lateur schrieb:
>
> Jorge Godoy wrote:
>
> >Using ISO-8859-1, there's no error message but the output from
> >Data::Dumper shows me that "José Alguém" becomes "José Alguém".
>
> Well, that's ISO-Latin-1 turned into UTF8. You need to convert it back
> to ISO-Latin-1.
>
> Now, I haven't really found a module which makes that easy.
> Unicode::Map, or something like it, is supposed to work, but I haven't
> tried any of those. I have, until now, always used my own home grown
> solution. Er... Unicode::MapUTF8 looks promising.
If you're using Perl 5.6, you might want to check
perldoc unicode
Otherwise, you could use UTF8::String, IIRC.
--
Christian Kirsch
ck@held.mind.de ck@ix.heise.de
Tel +49-30-78702288 +49-511-5352-590
Fax +49-30-78702289 KEINE ANNAHME VON DOC-DATEIEN
------------------------------
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 4814
**************************************