[22298] in Perl-Users-Digest
Perl-Users Digest, Issue: 4519 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 6 03:08:09 2003
Date: Thu, 6 Feb 2003 00:06:58 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 6 Feb 2003 Volume: 10 Number: 4519
Today's topics:
Re: @{undef} behaves different. Why? (Randal L. Schwartz)
Re: Attachments show in body, but only with Kmail (David Efflandt)
Calling subroutines from scalars <rpdaly@earthlink.net>
Re: Calling subroutines from scalars <mgjv@tradingpost.com.au>
Re: Calling subroutines from scalars (Jay Tilton)
Re: Calling subroutines from scalars <goldbb2@earthlink.net>
Re: Crossposting (was: Fetchrow Question) <jurgenex@hotmail.com>
Re: Help with arrays and such, please. <jurgenex@hotmail.com>
Re: Help with arrays and such, please. <novastar@dtdns.net.nospam>
Re: just installed ActivePerl5.8, then? <mgjv@tradingpost.com.au>
Re: just installed ActivePerl5.8, then? <goldbb2@earthlink.net>
Re: PERL + SQL (fredduc)
Perl Search Engine Script <tylercruz@hotmail.com>
Re: reference to abc.pl?a=b does not display as html in <jurgenex@hotmail.com>
Seeking HTML crunching tool (Allan Cady)
Re: Seeking HTML crunching tool <jurgenex@hotmail.com>
Re: sort, my concoction of <mgjv@tradingpost.com.au>
Re: strange localtime return (Shadowfax)
Re: string in datei <jurgenex@hotmail.com>
Re: string in datei (Tad McClellan)
Wrap a line at x characters <bhjp@spookyworld.dnsalias.com>
Re: Wrap a line at x characters (Jay Tilton)
Re: Wrap a line at x characters <noreply@gunnar.cc>
Re: Wrap a line at x characters (Walter Roberson)
Re: Wrap a line at x characters <mgjv@tradingpost.com.au>
Re: Wrap a line at x characters (Tad McClellan)
Re: Wrap a line at x characters <wsegrave@mindspring.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 05 Feb 2003 14:23:46 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: tadmc@augustmail.com
Subject: Re: @{undef} behaves different. Why?
Message-Id: <86k7gebc3x.fsf@red.stonehenge.com>
>>>>> "Tad" == Tad McClellan <tadmc@augustmail.com> writes:
Tad> Uri wrote a nice article about autoviv:
Tad> http://tlc.perlarchive.com/articles/perl/ug0002.shtml
And I wrote something similar from a different perspective:
<http://www.stonehenge.com/merlyn/UnixReview/col44.html>
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 6 Feb 2003 03:09:05 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Attachments show in body, but only with Kmail
Message-Id: <slrnb43keh.f2.efflandt@typhoon.xnet.com>
On 3 Feb 2003 16:50:29 -0800, Robert <robert@nrc.net> wrote:
> I have a PERL script that mails an attachment of a .csv file. It works
> fine with Outlook, Outlook Express, Incredimail, Netscape, and The
> Bat. However Kmail with Linux shows the attachment in the mail body,
> NOT attaching it at all. Can someone tell me why that may be
> happening? Any help is greatly appreciated.
Are you using MIME::Lite module? What MIME Type or Disposition are you
setting for the attachment?
--
David Efflandt - All spam ignored http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Thu, 06 Feb 2003 02:32:15 GMT
From: rdaly <rpdaly@earthlink.net>
Subject: Calling subroutines from scalars
Message-Id: <jsh34v00uttc8hvgig7rkge9aukn64j50b@4ax.com>
Can someone show me a way to call a subroutine from a scalar. For
example, I have an array that lists 3 filenames. I need to call a
different subroutine based on the filename. Please look at the sample
snippet:
@dncs = qw /file1.txt file2.txt file3.txt/;
for (@dncs) {
# just get the digit
($num = $_) =~ s/.+(\d).+/$1/;
# Now call the subroutine.
$subr = "dnc$num()";
$subr; # This doesn't work
}
sub dnc1 {
}
sub dnc2 {
}
sub dnc3 {
}
Any insight would be appreciated.
------------------------------
Date: Thu, 06 Feb 2003 02:51:19 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Calling subroutines from scalars
Message-Id: <slrnb43jd7.se5.mgjv@verbruggen.comdyn.com.au>
On Thu, 06 Feb 2003 02:32:15 GMT,
rdaly <rpdaly@earthlink.net> wrote:
> Can someone show me a way to call a subroutine from a scalar. For
> example, I have an array that lists 3 filenames. I need to call a
> different subroutine based on the filename. Please look at the sample
> snippet:
I suspect that you really want a lookup table, not what you're asking
for...
> @dncs = qw /file1.txt file2.txt file3.txt/;
> for (@dncs) {
> # just get the digit
> ($num = $_) =~ s/.+(\d).+/$1/;
>
> # Now call the subroutine.
> $subr = "dnc$num()";
> $subr; # This doesn't work
> }
This could work, but I'm not going to tell you how. It's not how this
problem should be solved.
> sub dnc1 {
> }
> sub dnc2 {
> }
> sub dnc3 {
> }
>
> Any insight would be appreciated.
You could use an array, since you seem to have numeric lookup keys:
@lookup[1, 2, 3] = (\&dnc, \&dnc2, \&dnc3);
For a more generic, and probably better, way, use a hash:
%lookup = (
key1 => \&dnc1,
key2 => \&dnc2,
...
);
You can even do it without the dnc1 and dnc2 names and define the
subroutines directly in your lookup table, anonymously:
%lookup = (
key1 => sub { .. your code goes here .. },
key2 => sub { .. other code goes here ..},
...
);
Then you retrieve the code reference[1] once you have the key:
my $coderef = $lookup{$key} or die "Got no code to run!";
and run it with the arguments you want:
&$coderef($arg1, $arg2 ...); # I don't really like this
or
$coderef->($arg1, $arg2 ...);
See the perlref documentation for more information about references,
and specifically these things. The perlsub documentation also has some
information.
there are many more tricks possible, some of which could generate
anonymous code references based on some criteria. This could work well
if the three subs all basically do the same, except for small
differences. But since we don't know anything about that bit, it'd be
presumptuous to try to advise you there.
Martien
[1] You don't _have_ to retrieve it, since you can use it directly,
however, your code generally is easier to understand and work with if
you do, and it gives you a good spot to check whether there is a code
reference there.
--
|
Martien Verbruggen | We are born naked, wet and hungry. Then
Trading Post Australia | things get worse.
|
------------------------------
Date: Thu, 06 Feb 2003 03:00:00 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Calling subroutines from scalars
Message-Id: <3e41cba3.189849281@news.erols.com>
rdaly <rpdaly@earthlink.net> wrote:
: Can someone show me a way to call a subroutine from a scalar. For
: example, I have an array that lists 3 filenames. I need to call a
: different subroutine based on the filename. Please look at the sample
: snippet:
:
: @dncs = qw /file1.txt file2.txt file3.txt/;
: for (@dncs) {
: # just get the digit
: ($num = $_) =~ s/.+(\d).+/$1/;
Oof. If all you need is the captured digit, don't bother with the
s/// jazz. Just capture it.
my($num) = /.+(\d).+/;
: # Now call the subroutine.
: $subr = "dnc$num()";
: $subr; # This doesn't work
: }
:
: sub dnc1 { }
: sub dnc2 { }
: sub dnc3 { }
:
: Any insight would be appreciated.
You're grasping for what's called a "symbolic reference," and you're
not ready to open that Pandora's box of evils yet. See "How can I use
a variable as a variable name?" in perlfaq7.
Use the hash, Luke.
my %call = (
'1' => \&dnc1,
'2' => \&dnc2,
'3' => \&dnc3,
);
for (@dncs) {
my($num) = /.+(\d).+/;
$call{$num}->();
}
Yeah, ok, if the subroutine names are identified by simple digits, an
array would work too, e.g.
my @call = \( undef, &dnc1, &dnc2, &dnc3 );
for (@dncs) {
my($num) = /.+(\d).+/;
$call[$num]->();
}
but the hash is a more generalized solution.
------------------------------
Date: Thu, 06 Feb 2003 01:56:26 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Calling subroutines from scalars
Message-Id: <3E42071A.5447418@earthlink.net>
Jay Tilton wrote:
[snip]
> my @call = \( undef, &dnc1, &dnc2, &dnc3 );
While it's clear what you intend here, I don't think that that
works...(though I haven't tested to find out if it does or doesn't).
I would suggest that you write it out the normal way:
my @call = ( undef, \&dnc1, \&dnc2, \&dnc3 );
--
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"
------------------------------
Date: Thu, 06 Feb 2003 02:23:55 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Crossposting (was: Fetchrow Question)
Message-Id: <%Gj0a.5450$011.4034@nwrddc01.gnilink.net>
Benjamin Goldberg wrote:
> mgarrish wrote:
>> Benjamin Goldberg wrote:
>>>
>>> Young folks know little, but think they know everything.
>>>
>>> Sadly, some old folks are the same.
>>>
>>
>> And then there's me, whose job it is to bring these people down a few
>> notches...
>
> Err, no, you're in one of those two categories I just mentioned.
>
> Hmm, actually, you're doing a pretty good job of bringing yourself
> down a few notches, so perhaps you're right about what you're doing.
> You're merely mistaken in your belief that you aren't in those
> categories.
>
> Flaming folks like uri shows just how foolish you are, and decreases
> the amount of respect you have (had) in the community.
Ben, while I admire your enthusiasm, you know how the old saying goes:
Don't argue with an idiot. He brings you down to his level and then wins
easily because of his greater experience.
jue
------------------------------
Date: Thu, 06 Feb 2003 02:14:10 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Help with arrays and such, please.
Message-Id: <Sxj0a.5425$011.2050@nwrddc01.gnilink.net>
Perl Dude wrote:
> I'm sure that the method I'm using is not the correct one. I'm
> an "advanced newbie" when it comes to this stuff.
>
> I'm parsing out my mail log, looking for attempted relays from
> spammers via the same IP so I can report them to the proper
> authorities. The log file is chronological, so spammer A may
> have several hits per day interspersed with hits from spammers
> B, C, and D.
>
> I'm currently parsing the log and obtaining three items... time,
> address, and relay.
>
> 01:24 ispam@spam.com 123.123.123.123
> 01:26 uspam@spamsucks.com 0.0.0.0
> 01:30 hespams@toomuchspam.com 123.123.123.123
> 01:45 spam@dev.null 123.1.2.3
>
> and so on.
>
> For lack of experience and knowledge they are going into three
> seperate arrays; @Time, @Address, @Relay.
A better data structure would be a single array containing references to
hashes (short AoH = Array of Hashes), where each hash consists of
{time => '.....',
address => '.....',
relay => '.....'}
> What I need to do is sort this so that as I pass through the
> array of hits, I get a report of times and spammers of each
> relay address.
Then you problem is reduced to two steps:
First sort that array by the relay address (please see "perldoc -q sort" for
details; basically use something like
{$a->{relay} cmp $b->{relay}}
as the comparison function.
And then just loop through the array. Becasue the same relay values are
bunched together it's easy to tell when you reach the next relay block.
Another approach is to use a hash of array of hash.
The top level hash has the relay values as keys. And it points to a list
(=array) of all time/address combinations when this relay accessed you site.
To fill this hash just loop through your existing data structure once.
And then all the records for any specific relay are right there
Personally I like the second approach even better.
jue
------------------------------
Date: Thu, 6 Feb 2003 09:32:55 +0200
From: "George Bouras" <novastar@dtdns.net.nospam>
Subject: Re: Help with arrays and such, please.
Message-Id: <1044516771.353208@athprx02>
"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3E41A90D.24C0A51C@earthlink.net...
> Perl Dude wrote:
> >
> > I'm sure that the method I'm using is not the correct one. I'm
> > an "advanced newbie" when it comes to this stuff.
> >
> > I'm parsing out my mail log, looking for attempted relays from
> > spammers via the same IP so I can report them to the proper
> > authorities. The log file is chronological, so spammer A may
> > have several hits per day interspersed with hits from spammers
> > B, C, and D.
> >
> > I'm currently parsing the log and obtaining three items... time,
> > address, and relay.
> >
> > 01:24 ispam@spam.com 123.123.123.123
> > 01:26 uspam@spamsucks.com 0.0.0.0
> > 01:30 hespams@toomuchspam.com 123.123.123.123
> > 01:45 spam@dev.null 123.1.2.3
> >
> > and so on.
> >
> > For lack of experience and knowledge they are going into three
> > seperate arrays; @Time, @Address, @Relay.
> >
> > What I need to do is sort this so that as I pass through the
> > array of hits, I get a report of times and spammers of each
> > relay address.
> >
> > Spam attempts from 123.123.123.123:
> > 01:24 ispam@spam.com
> > 01:30 hespams@toomuchspam.com
> >
> > Spam attempts from 0.0.0.0:
> > 01:26 uspam@spamsucks.com
> >
> > Spam attempts from 123.1.2.3:
> > 01:45 spam@dev.null
> [snip]
>
> my %data;
> while( <> ) {
> (my @data = split) == 3 or next;
> push @{ $data[2] } => [@data[0,1]];
> }
> while( my ($spammer, $time_email) = each %data ) {
> print "Spam attempts from $spammer:\n";
> print " @$_\n" for @$time_email;
> print "\n";
> }
> __END__
> [untested]
> --
> "So, who beat the clueless idiot today?"
> "Well, we flipped for it, but when Kuno
> landed, he wasn't in any shape to fight."
> "Next time, try flipping a *coin.*"
Nice code.
------------------------------
Date: Thu, 06 Feb 2003 02:32:29 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: just installed ActivePerl5.8, then?
Message-Id: <slrnb43i9t.se5.mgjv@verbruggen.comdyn.com.au>
On Wed, 5 Feb 2003 21:58:54 +0000 (UTC),
Ben Morrow <mauzo@mimosa.csv.warwick.ac.uk> wrote:
> samj@eisa.net.au (samphdauto) wrote:
[snip lots of confusion]
> I would apologise for the facetiousness[1] but you don't seem to have tried
> very hard to find out. If finding such things out is really beyond you then
> may I suggest that Perl may well be as well?
> [1] sp? That's what /usr/share/dict/words says, but I thought it had an ae in.
> Is this a UK/US thing, or am I just wrong?
It is not a US/UK thing. facetious is the correct spelling on both
sides of that pond, as well as here.
Did you think it was faecetious? If that was a word, it'd probably be
derived from faeces, and it would probably mean something slightly,
but not alltogether, different.
Martien
--
|
Martien Verbruggen | In the fight between you and the world, back
Trading Post Australia | the world - Franz Kafka
|
------------------------------
Date: Thu, 06 Feb 2003 01:51:45 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: just installed ActivePerl5.8, then?
Message-Id: <3E420601.E4738541@earthlink.net>
Martien Verbruggen wrote:
>
> On Wed, 5 Feb 2003 21:58:54 +0000 (UTC),
> Ben Morrow <mauzo@mimosa.csv.warwick.ac.uk> wrote:
> > samj@eisa.net.au (samphdauto) wrote:
>
> [snip lots of confusion]
>
> > I would apologise for the facetiousness[1] but you don't seem to
> > have tried very hard to find out. If finding such things out is
> > really beyond you then may I suggest that Perl may well be as well?
>
> > [1] sp? That's what /usr/share/dict/words says, but I thought it had
> > an ae in. Is this a UK/US thing, or am I just wrong?
>
> It is not a US/UK thing. facetious is the correct spelling on both
> sides of that pond, as well as here.
>
> Did you think it was faecetious? If that was a word, it'd probably be
> derived from faeces, and it would probably mean something slightly,
> but not alltogether, different.
Hey, you never know -- look at where the word shyster comes from. :)
--
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"
------------------------------
Date: 5 Feb 2003 23:20:41 -0800
From: fredduc@hotmail.com (fredduc)
Subject: Re: PERL + SQL
Message-Id: <7f151cfe.0302052320.5fc2055@posting.google.com>
Hi all,
Thx for all these answers! I will look forward for today to do some of
these things!!!
Fred
------------------------------
Date: Thu, 06 Feb 2003 07:56:34 GMT
From: "Tyler Cruz" <tylercruz@hotmail.com>
Subject: Perl Search Engine Script
Message-Id: <Syo0a.196290$sV3.6911423@news3.calgary.shaw.ca>
Hi,
Here is my problem. This is a portion from a search engine for reviews. The
problem is that our title of reviews are in the format: "The Matrix" for
example, so when somebody searches for Matrix, they can see Matrix easily.
However if they search for The Matrix, there is no title called The Matrix.
To try this out, you can go to http://www.movie-vault.com and see for
yourself.
So what I want to do is put an if statement, questioning if the title begins
with "the " and if it does, then just search for everything after it. I know
this is extremely basic, but I haven't done ANY Perl stuff in years - and
could really use the help. Here is the code snipit:
if ($grep eq "Title") {
$sth = $dbh->prepare("select title, director, writer, year, movieid from
reviews where title like \"%$searchstring%\" order by 1") || die "Oops";
}
If, for some reason, you need the entire code for the search area, it is
here:
Thanks in advance.
if ($action eq "grep")
{ my $grep = $cgi->param("grep");
my $searchstring = $cgi->param("searchstring");
my $sth;
if ($grep eq "Title") {
$sth = $dbh->prepare("select title, director, writer, year, movieid from
reviews where title like \"%$searchstring%\" order by 1") || die "Oops";
}
if ($grep eq "Director")
{ $sth = $dbh->prepare("select title, director, writer, year, movieid from
reviews where director like \"%$searchstring%\" order by 2") || die
"Oops"; }
if ($grep eq "Writer")
{ $sth = $dbh->prepare("select title, director, writer, year, movieid from
reviews where writer like \"%$searchstring%\" order by 3") || die "Oops"; }
if ($grep eq "Year")
{ $sth = $dbh->prepare("select title, director, writer, year, movieid from
reviews where year like \"%$searchstring%\" order by 4") || die "Oops"; }
if (!$sth) {print "Not a valid Search type"; die;}
$sth->execute();
my ($title,$movieid,$year,$writer,$director);
$sth->bind_columns( \$title, \$director,\$writer,\$year,\$movieid );
print "Search results on $grep - <B>$searchstring</B><TABLE BORDER='2'>";
print
"<TR><TD><B>Title</B></TD><TD><B>Director</B></TD><TD><B>Writer</B></TD><TD>
<B>Year</B></TD></TR>";
while( $sth->fetch() )
{ print "<TR><TD><A
HREF=\"list.pl?action=moviereview&movieid=$movieid\">$title</A></TD><TD><A
HREF=\"list.pl?action=moviereview&movieid=$movieid\">$director</A></TD><TD><
A
HREF=\"list.pl?action=moviereview&movieid=$movieid\">$writer</A></TD><TD><A
HREF=\"list.pl?action=moviereview&movieid=$movieid\">$year</A></TD></TR>\n";
}
print"</TABLE>";
$sth->finish();
}
------------------------------
Date: Thu, 06 Feb 2003 02:31:47 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: reference to abc.pl?a=b does not display as html in N6
Message-Id: <nOj0a.7298$yt6.3032@nwrddc04.gnilink.net>
G.G. Campbell wrote:
> I have a perl script which returns html text.
Cool. Then your Perl script works fine, doesn't it?
> But N6 interprets the following address as perl
> and asks whether to start perl.
>
> http://isccp.cira.colostate.edu/scripts/monmat.pl?yrmn=8505
Have you tried asking in a NG that actually deals with N6
> This works in IE6.
>
> The perl script it self begins with
> print "Content-type: text/html\n\n";
So?
> please reply to campbell@cira.colostate.edu
> as I do not visit here often.
Well, that is certainly yet another problem.
jue
------------------------------
Date: 5 Feb 2003 19:19:22 -0800
From: allancady@yahoo.com (Allan Cady)
Subject: Seeking HTML crunching tool
Message-Id: <d563b154.0302051919.67f7cca6@posting.google.com>
I'm looking for a tool of some sort that can be used to perform
scripted modifications to HTML files. For example, to remove the
first <table>...</table> from each of a set of files, or to remove all
table cells with WIDTH=1.
Can anyone recommend such a tool? (Or a better group to post this
to?)
This is kind of a regular-expressiony sort of thing, in the sense that
I'd like to be able to express a substitution rule and have it execute
that rule on files. But REs don't understand nested constructs like
HTML.
I'm working in a Windows environment. I have Perl installed, so I
could use that, but I'm barely literate with it yet, and since regular
expressions won't do the job, I'm not sure that Perl is the right tool
for this.
I looked at using the Internet Explorer API, and manipulating the
document object model, but that doesn't seem very well suited for what
I'm trying to do.
Suggestions, anyone? Thanks.
Allan
------------------------------
Date: Thu, 06 Feb 2003 03:46:50 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Seeking HTML crunching tool
Message-Id: <KUk0a.1114$5g7.254@nwrddc02.gnilink.net>
Allan Cady wrote:
> I'm looking for a tool of some sort that can be used to perform
> scripted modifications to HTML files. For example, to remove the
> first <table>...</table> from each of a set of files, or to remove all
> table cells with WIDTH=1.
>
> Can anyone recommend such a tool? (Or a better group to post this
> to?)
This Question is Asked Frequently, please consult 'perldoc -q HTML':
"How do I remove HTML from a string?"
Although the title doesn't seem to match your problem exactly in reality you
do have the same problem and the answer applies to your question, too.
jue
------------------------------
Date: Thu, 06 Feb 2003 02:18:18 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: sort, my concoction of
Message-Id: <slrnb43hfa.se5.mgjv@verbruggen.comdyn.com.au>
On 05 Feb 2003 08:18:06 GMT,
Abigail <abigail@abigail.nl> wrote:
> Martien Verbruggen (mgjv@tradingpost.com.au) wrote on MMMCDXLIV September
> MCMXCIII in <URL:news:slrnb40hrt.se5.mgjv@verbruggen.comdyn.com.au>:
> %%
> %% Using things like [:upper:], [:lower:], [:alpha:], [:alnum:] etc in a
> %% regular expression character class is much more reliable.
>
> Some some values of 'reliable'.
Indeed.
> They aren't very usefull if you maintain
> a module that should also work on pre-5.6 perl.
I know. I maintain one of those modules. I used to use POSIX::isgraph
in that module, but that broke in 5.8.0. I tried to switch to
[[:graph:]], but need to keep things compatible with 5.005_03. Now I
have ugly code which needs to eval strings in a BEGIN block to get
around these issues.
> Furthermore, [:upper:]
> and [:lower:] are *not* equivalent to [A-Z] and [a-z].
Which is part of the point I was trying to make, although I admit I
made it rather weakly.
> If Unicode is
> in effect [:upper:] matches all uppercase letters, and [:lower:]
> matches all lowercase letters. That's why in Regexp::Common I use
> [a-z], [A-Z] and [0-9] instead of [:upper:], [:lower:], \w or \d.
I am a bit confused about what that achieves or avoids. To me, [a-z]
means all characters between a and z, inclusive, and [[:lower:]] means
all lowercase characters. In certain locales those two do not map
neatly onto each other (and on certain platforms there might even be
more problems, but see later). Do you mean to say that Regex::Common
uses a-z instead of [[:lower:]] because that's what most people "expect"?
> I also thought that '[a-z]' and such was special cased on EBCDIC
> platforms to match all lowercase letters, but I don't have the time
> to search the manual for it right now.
ISTR that there was some discussion and a lot of confusion about this
at some point, either here or on the p5p list. The range of numerical
values of a-z (and A-Z) in the various EBCDIC tables has gaps in it,
however, the confusion stemmed from the fact that some people seemed
to think that Perl compensated for that in character classes and
ranges. One of the things that confused people was the chr()
documentation, which I see has been updated in 5.8.0. I can't recall
whether there ever was something authoritative about what character
classes and ranges did or didn't do.
Martien
--
|
Martien Verbruggen | You can't have everything, where would you
Trading Post Australia | put it?
|
------------------------------
Date: 5 Feb 2003 23:04:15 -0800
From: shadowfax@optonline.net (Shadowfax)
Subject: Re: strange localtime return
Message-Id: <22e9b972.0302052304.2b75c7fd@posting.google.com>
Thanks all for the reply.
I make some progress but stuck on below error again, it seems all the
variable was initialized already.
"Use of uninitialized value in addition (+) at E:\temp\rename.pl line
29 "
Thanks,
Shadowfax
use strict;
use warnings;
use Time::localtime;
use File::stat;
my %file_date=();
my $YYYYMMDD;
my $org_file;
my $mtime;
my $new_filename;
my %month_translate=("Jan","01","Feb","02","Mar","03","Apr","04","May","05","Jun","06","Jul","07","Aug","08","Sep","09","Oct","10","Nov","11","Dec","12");
my $org_dir="E:/temp/v";
opendir(DIR,$org_dir)||die "can't open original directory $org_dir" ;
my @org_files=readdir(DIR) ;
closedir(DIR) ;
foreach $org_file(@org_files)
{
$mtime=ctime(stat("$org_dir/$org_file")->mtime);
my ($wday,$mon,$mday,$min,$year)=split(/\s+/,$mtime);
$YYYYMMDD = sprintf ("%4d%02d%02d", $year, $month_translate{$mon},
$mday);
# print "$org_file\n";
# print "Modified Time: $YYYYMMDD\n";
while (undef $file_date{$YYYYMMDD}) {
$file_date{$YYYYMMDD}=0;
}
$file_date{$YYYYMMDD} = $file_date{$YYYYMMDD} + 1;
$new_filename=$YYYYMMDD."_".$file_date{$YYYYMMDD};
rename $org_file,$new_filename;
}
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb3vcjb.6q2.tadmc@magna.augustmail.com>...
> Shadowfax <shadowfax@optonline.net> wrote:
>
> > But when I
> > run the script, surprisingly
>
>
> It is not surprising, it is exactly as it is supposed to be.
>
> If you simply guess at what a function is supposed to do, then
> you are pretty much asking for surprises.
>
>
> > I saw the $year return as "691131", did I
> > do something wrong ?
>
>
> Yes. You did not read the documentation for the functions that
> you are using.
>
> That is the programming equivalent of signing a contract without
> reading it. You are asking for pain if you do that, so don't do that. :-)
>
>
> > $org_dir="E:\\temp\\testfolder";
>
>
> You do not need to use silly slashes:
>
> $org_dir='E:/temp/testfolder';
>
>
>
> > @org_files=readdir(DIR) ;
>
>
> > $mtime=(stat($org_file))[9] ;
>
>
> perldoc -f readdir
>
> If you're planning to filetest the return values
> out of a "readdir", you'd better prepend the
> directory in question. Otherwise, because we
> didn't "chdir" there, it would have been testing
> the wrong file.
>
>
> So make that:
>
> $mtime=(stat("$org_dir/$org_file"))[9] ;
>
>
> > my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime
> > mtime;
> ^^
> ^^ where is the dollar sign?
>
>
> Please see the Posting Guidelines that are posted here frequently:
>
> Do not re-type Perl code
> Use copy/paste or your editor's "import" function rather than
> attempting to type in your code. If you make a typo you will get
> followups about your typos instead of about the question you are
> trying to get answered.
>
>
> You should read the docs for the functions that you use:
>
> perldoc -f localtime
>
> $year is the number of years since 1900. That is,
> $year is 123 in year 2023.
>
> ...
>
> The proper way to get a complete 4-digit year is
> simply:
>
> $year += 1900;
------------------------------
Date: Thu, 06 Feb 2003 02:48:26 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: string in datei
Message-Id: <_1k0a.5519$011.2775@nwrddc01.gnilink.net>
Ben Morrow wrote:
> abigail@abigail.nl wrote:
>> Huh? This isn't en.comp.lang.perl.misc.
>
> No, this is comp.lang.perl.misc, which is by implication
> us.comp.lang.perl.misc.
No, by no means! What gave you that idea?
This is a world-wide group. If you want a US-only group please feel free to
create one.
It's statements like these which make Americans appear to be arrogant,
non-caring, and trying to dominate the 'rest of the world' (which is a
rather egocentric term in itself).
> In the US they speak (some approximation to) English.
Or Spanish or Japanese or Chinese or German or ....
> Apart from anything else, discussions in one group in several
> languages rapidly get very confusing and nearly impossible to follow.
> If you speack Deutsch, feel free to read de.comp.lang.perl.misc (or
> whatever).
With that I wholeheartedly agree.
jue
------------------------------
Date: Wed, 5 Feb 2003 22:47:48 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: string in datei
Message-Id: <slrnb43q7k.d0f.tadmc@magna.augustmail.com>
Jürgen Exner <jurgenex@hotmail.com> wrote:
> Ben Morrow wrote:
>> abigail@abigail.nl wrote:
>>> Huh? This isn't en.comp.lang.perl.misc.
>>
>> No, this is comp.lang.perl.misc, which is by implication
>> us.comp.lang.perl.misc.
>
> No, by no means! What gave you that idea?
> This is a world-wide group. If you want a US-only group please feel free to
> create one.
>
> It's statements like these which make Americans appear to be arrogant,
Yep. I'm embarrassed by your attitude in this thread Ben.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 06 Feb 2003 02:15:48 -0000
From: Sean <bhjp@spookyworld.dnsalias.com>
Subject: Wrap a line at x characters
Message-Id: <v43hak4icl1ce4@corp.supernews.com>
Hello,
This is probably a simple regex problem, but I'm not sure how to approach
it. I have a string of text, say 128 characters long and I'm looking to
insert line breaks every x characters. Could someone clue me in on how I
may accomplish this?
Thanks,
Sean
--
\___/ Sean Keplinger
|o,o| skeplin at one dot net
\/ ) http://spookyworld.dnsalias.com
----mm-----------------------------------
------------------------------
Date: Thu, 06 Feb 2003 02:34:11 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Wrap a line at x characters
Message-Id: <3e41c951.189254661@news.erols.com>
Sean <bhjp@spookyworld.dnsalias.com> wrote:
: This is probably a simple regex problem, but I'm not sure how to approach
: it.
First thing to do is see if it's already been solved.
: I have a string of text, say 128 characters long and I'm looking to
: insert line breaks every x characters. Could someone clue me in on how I
: may accomplish this?
use Text::Wrap;
------------------------------
Date: Thu, 06 Feb 2003 02:42:36 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Wrap a line at x characters
Message-Id: <wYj0a.9722$LY2.587413@newsc.telia.net>
Sean wrote:
> I have a string of text, say 128 characters long and I'm looking to
> insert line breaks every x characters. Could someone clue me in on how I
> may accomplish this?
If I were you, I'd check out Text::Wrap at CPAN, or some similar module.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 6 Feb 2003 02:42:57 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Wrap a line at x characters
Message-Id: <b1si3h$aop$1@canopus.cc.umanitoba.ca>
In article <v43hak4icl1ce4@corp.supernews.com>,
Sean <bhjp@spookyworld.dnsalias.com> wrote:
:This is probably a simple regex problem, but I'm not sure how to approach
:it. I have a string of text, say 128 characters long and I'm looking to
:insert line breaks every x characters. Could someone clue me in on how I
:may accomplish this?
s/(.{128})/\1\n/g
should give you the general jist. It's not exactly right, though,
in that if your string happens to be exactly a multiple of 128 and
already ends with \n, you will end up with a double \n at the end.
I would have to ask whether you really want to split every 128
characters? Or do you want to split at "a nice place" (e.g., whitespace)
with the resulting strings being -at most- 128 characters?
And if so, what do you want done if there doesn't happen to be a
word break within 128 characters?
--
IEA408I: GETMAIN cannot provide buffer for WATLIB.
------------------------------
Date: Thu, 06 Feb 2003 02:54:46 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Wrap a line at x characters
Message-Id: <slrnb43jjm.se5.mgjv@verbruggen.comdyn.com.au>
On Thu, 06 Feb 2003 02:15:48 -0000,
Sean <bhjp@spookyworld.dnsalias.com> wrote:
> Hello,
>
> This is probably a simple regex problem, but I'm not sure how to approach
> it. I have a string of text, say 128 characters long and I'm looking to
> insert line breaks every x characters. Could someone clue me in on how I
> may accomplish this?
$string =~ s/(.{$n})/$1\n/g;
However, you leave many, many things unspecified. Can a break occur
between any two characters, or are you really looking for word-wrap
(see text::Wrap, in that case). What if there are already line breaks?
And more of those questions.
Martien
--
|
Martien Verbruggen | True seekers can always find something to
Trading Post Australia | believe in.
|
------------------------------
Date: Wed, 5 Feb 2003 22:41:48 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Wrap a line at x characters
Message-Id: <slrnb43psc.d0f.tadmc@magna.augustmail.com>
Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:
> s/(.{128})/\1\n/g
You should always enable warnings when developing Perl code.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 5 Feb 2003 23:02:57 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Wrap a line at x characters
Message-Id: <b1sqgv$6te$1@slb6.atl.mindspring.net>
"Sean" <bhjp@spookyworld.dnsalias.com> wrote in message
news:v43hak4icl1ce4@corp.supernews.com...
> Hello,
>
> This is probably a simple regex problem, but I'm not sure how to approach
> it. I have a string of text, say 128 characters long and I'm looking to
> insert line breaks every x characters. Could someone clue me in on how I
> may accomplish this?
You might find Text::Autoformat to be of interest.
OTOH, why use a module at all? You could use format and write (see Camel
Book).
Bill Segraves
------------------------------
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 4519
***************************************