[30242] in Perl-Users-Digest
Perl-Users Digest, Issue: 1485 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 25 17:22:05 2008
Date: Fri, 25 Apr 2008 14:21:37 -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 Fri, 25 Apr 2008 Volume: 11 Number: 1485
Today's topics:
Re: use of DBI; I am getting multiple error messages mi (Ben Bullock)
Re: use of DBI; I am getting multiple error messages mi (Ben Bullock)
Re: use of DBI; I am getting multiple error messages mi (Ben Bullock)
Re: use of DBI; I am getting multiple error messages mi xhoster@gmail.com
Re: use of DBI; I am getting multiple error messages mi xhoster@gmail.com
Re: use of DBI; I am getting multiple error messages mi <rvtol+news@isolution.nl>
Re: use of DBI; I am getting multiple error messages mi xhoster@gmail.com
Re: use of DBI; I am getting multiple error messages mi <rvtol+news@isolution.nl>
Re: use of DBI; I am getting multiple error messages mi <rvtol+news@isolution.nl>
Re: use of DBI; I am getting multiple error messages mi <someone@example.com>
Re: use of DBI; I am getting multiple error messages mi <RedGrittyBrick@SpamWeary.foo>
Re: use of DBI; I am getting multiple error messages mi <RedGrittyBrick@SpamWeary.foo>
Re: use of DBI; I am getting multiple error messages mi <m@rtij.nl.invlalid>
Using a file's modification date in the filename cca.johnson@gmail.com
Re: Using a file's modification date in the filename <jurgenex@hotmail.com>
Re: Using a file's modification date in the filename xhoster@gmail.com
Re: Using a file's modification date in the filename cca.johnson@gmail.com
Re: Using a file's modification date in the filename <gerry@nowhere.ford>
Re: WWW::Mechanize doesn't always follow_link(text <mikaelb@df.lth.se>
Re: WWW::Mechanize doesn't always follow_link(text <john@castleamber.com>
Re: WWW::Mechanize doesn't always follow_link(text <mikaelb@df.lth.se>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 24 Apr 2008 14:10:08 +0000 (UTC)
From: benkasminbullock@gmail.com (Ben Bullock)
Subject: Re: use of DBI; I am getting multiple error messages mixed in with ?the correct output.
Message-Id: <fuq4c0$b7o$1@ml.accsnet.ne.jp>
Ted <r.ted.byers@rogers.com> wrote:
>> Try running the following script to clarify what this means:
>>
>> #!/usr/bin/perl
>> use warnings;
>> use strict;
>> my $a;
>> my $b = "";
>> print "a is defined\n" if defined($a);
>> print "b is defined\n" if defined($b);
>>
>> Here $b is a "real null string" and $a is undefined.
Excuse me, this should say '$b is a "defined null string"' not "real".
> No. $b holds an empty string, and empty strings are not the same thing
> as NULL (as defined in either C++ and Java or SQL).
But I'm not talking about C++ or Java or SQL. I'm talking about
Perl. This is a perl newsgroup. "" is what the book you're referring
to means by a "defined null string", as opposed to an undefined value.
> But that is exactly what Wall et al. said about undefined. I learned
> much of what I know about Perl from their book, and they said that an
> undefined variable is one that does not have a valid string, number or
> reference, and that exactly describes a variable that has not yet been
> initialized. The empty string is a valid string in all of the
> languages I use, and it means something quite different from a SQL
> null.
We're not talking about the empty string any more, the above is
talking about an undefined value. As I pointed out in the two scripts,
$b="" and $b=undef are two totally different things.
>> > But ALL of these concepts are very different from the idea of NULL in
>> > SQL. For example, The book, from Osborne, "SQL: The complete reference"
>> > by James Groff and Paul Weinberg, described it as referring to data that
>> > is missing, unknown, or don't apply.
>>
>> Which seems to be exactly what the undefined value in Perl is, to me.
>>
> Then you're using a definition of the term that is quite different
> from what Wall et al. wrote about undefined. Where they wrong, or
> merely misleading?
Look at this kind of example:
my @arr = (undef, 1, 3, undef, 4);
If you then refer to $arr[3] you get the undefined value. So you can
assign it into a variable. What is more you can do things like
(undef, $x, $y) = @z;
to ignore the value of $z[0].
I don't know how that compares to SQL's NULL in detail, but it seems
to me that this refers to data that is "missing, unknown or does not
apply", thus from your statement this "seems to be exactly what the
undefined value in Perl is, to me", as I said.
>> > While NULL in SQL is different from
>> > numeric or string data, I see nothing in the idea that indicates it is a
>> > value that is not part of the normal range of values.
>>
>> Perhaps you can think of Perl's undef as being part of the normal range
>> of values, too.
>>
> In principal I'd have no problem with that, if it weren't for the fact
> that Wall et al. described them as referring to variables that were
> not initialized.
You keep on and on repeating this but I've already pointed out to you
that it doesn't mean that. Did you actually try running or even
reading those scripts I gave? You need to spend a lot more time
reading and writing Perl code and a lot less time in creating mounds
of verbiage.
>> > I see nothing similar between the idea of NULL in SQL and either null or
>> > undefined in the other languages.
>>
>> That's odd, because the more you talk about SQL's NULL, the more it looks
>> like Perl's undefined value to me.
>>
> Until now, I had seen nothing written about perl that suggested that
> Wall et al.'s description of undefined meant anything other than a
> reference to variables that had not yet been initialized, and that is
> a very different concept from SQL's NULL.
Please don't say "not yet" again, I've already given you counter
examples for that.
> Why would you object to my leveraging what I know in other languages
> to learn Perl?
Since you've replied to my post, I assume you're addressing this
comment to me, so let me say that I don't remember objecting to
that.
------------------------------
Date: Fri, 25 Apr 2008 00:27:05 +0000 (UTC)
From: benkasminbullock@gmail.com (Ben Bullock)
Subject: Re: use of DBI; I am getting multiple error messages mixed in with ?the correct output.
Message-Id: <fur8gp$j50$1@ml.accsnet.ne.jp>
Martijn Lievaart <m@rtij.nl.invlalid> wrote:
> On Thu, 24 Apr 2008 14:10:08 +0000, Ben Bullock wrote:
>> Excuse me, this should say '$b is a "defined null string"' not "real".
>
> No, $b is an empty string. Certainly not a null string. There is no such
> thing as a null string in perl. C++ has a null string concept IIRC, but
> Java and C don't, they allow the variable to be set to NULL, which in
> perl is setting it to undef.
You're taking this phrase out of context. If you go back and read the
previous messages in the thread, you'll see why I used the terminology
"defined null string".
------------------------------
Date: Fri, 25 Apr 2008 04:18:54 +0000 (UTC)
From: benkasminbullock@gmail.com (Ben Bullock)
Subject: Re: use of DBI; I am getting multiple error messages mixed in with ?the correct output.
Message-Id: <furm3e$m8r$1@ml.accsnet.ne.jp>
Ted <r.ted.byers@rogers.com> wrote:
> You know, this is precisely how I have conceived of undef working
> since I first read Wall et al. It is good to know I haven't grossly
> misunderstood it all this time.
It is very good to know that you understood everything correctly from
the beginning without anyone having to go to the trouble of explaining
it to you.
------------------------------
Date: 23 Apr 2008 22:18:56 GMT
From: xhoster@gmail.com
Subject: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
Message-Id: <20080423181858.824$Kn@newsreader.com>
Ted <r.ted.byers@rogers.com> wrote:
> On Apr 23, 5:23=A0pm, Ted Zlatanov <t...@lifelogs.com> wrote:
> >
> > The problem is that there are NULL values, which are undefined in the
> > DBI translation. =A0So this
> >
> > printf("%s%s", $i ? "," : "", $$ref[$i]);
> >
> > should be (for example)
> >
> > printf("%s%s", $i ? "," : "", $$ref[$i]||'NULL');
> >
>
> This would be a useful tidbit to add to the documentation. I hadn't
> expected a mature library like DBI to behave like this.
This is not DBI behavior. It is Perl behavior when undefined valued
are encountered. It is documented, just not in the DBI docs. It is not
reasonable to document every non-DBI problem that one may encounter when
using DBI in the DBI docs.
> I do not, for
> example, have to go through any such extra hoops when using JDBC with
> JSF. If a particular record set contains nulls in one or more columns
> in one or more records, JSF automagically displays it as an empty
> string;
If you want a language/framework that does just one thing well, then
keep using it rather than switching to a general purpose language. A
framework that is tightly designed to display stuff without any processing
might reasonably default to silently converting nulls to empty strings.
A general purpose language cannot reasonable make that decision silently.
Of course, you could alway turn off uninitialized value warnings if you
prefer to silence (potential) problems rather than fix them.
> something I have modified on occassion to display the string
> "N/A".
In mysql, a null string and an empty string are two different things.
Should both of them be converted to 'N/A', or just the null?
> And one thing I haven't found
> yet, which I am sure must be there somewhere, is how to set up a bulk
> insert. Can you point me in the right direction to see how to do that
> using DBI?
execute_array is supposed to do that. It does not work in all DBDs, and
does not work well in some of the others. Generally for maximum efficiency
of bulk loading, you need to bypass DBI and go to the bulk loading tool
that comes with (and is specific for) each database.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: 23 Apr 2008 22:37:58 GMT
From: xhoster@gmail.com
Subject: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
Message-Id: <20080423183801.453$xA_-_@newsreader.com>
Ted <r.ted.byers@rogers.com> wrote:
>
> Running it from within Emacs, all seems fine until I examine the
> output. All the calls to "STDOUT->print" behave correctly, and all
> the correct data is returned. I KNOW that database well, and the
> contents of the table I used for this test. ALL of the data in that
> table is returned. However, The correct output is punctuated about
> every 100 lines by hundreds of error messages: "Use of uninitialized
> value in printf at k:/MerchantData/MSDB.pl line 34." That is the
> printf in the for loop within the while loop. This increases the
> number of lines of output from precisely 529 to more than 1800! That
> is almost three times as much garbage as there is real data.
So? If there were only 0.0894 times as much "garbage", would that somehow
be better? It would probably be even worse, as then it might slip by
without even noticing that there is a problem.
>
> It is satisfying that I can get a little scriptlet to connect to the
> DB and get data so quickly, but it is frustrating that this extra
> garbage is present within the correct data
You failed to separate the STDOUT and STDERR streams. That is why the
warning messages and the real data are all mixed together. The exact
nature of the problem was described elsewhere. It is documented under
"perldiag".
> Where I want to go is to be able to retrieve data from the database,
> to use to structure requests made across the internet (to a data
> provider to which we have bought access), and then, when the data is
> received (as a large XML file) feed it into a pair of tables in the
> database (the tables will already exist in the DB, I am just unsure of
> how to use the DBI to do a bulk insert, or even if it can - haven't
> found that part of the documentation yet).
You can write the data into text files, and then use
DBI->do to invoke mysql's specific bulk loading method:
$dbh->do("load data local infile 'datafile.txt' into table foobar");
You will need to consult the mysql documentation for the
"load data local infile" command. DBI/DBD just provide a method of
executing the command, everything else is up to mysql.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Thu, 24 Apr 2008 02:04:28 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
Message-Id: <fuoq2r.1i8.1@news.isolution.nl>
Ted schreef:
> while (my $ref = $sth->fetchrow_arrayref) {
> for (my $i = 0; $i < $numFields; $i++) {
> printf("%s%s", $i ? "," : "", $$ref[$i]);
> }
> print "\n";
> }
while (my $ref = $sth->fetchrow_arrayref) {
print join(",", map defined() ? $_ : 'NULL', @$ref), "\n";
}
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 24 Apr 2008 01:39:28 GMT
From: xhoster@gmail.com
Subject: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
Message-Id: <20080423213931.981$bP@newsreader.com>
Ted <r.ted.byers@rogers.com> wrote:
> On Apr 23, 6:18=A0pm, xhos...@gmail.com wrote:
> > Ted <r.ted.by...@rogers.com> wrote:
> > > On Apr 23, 5:23=3DA0pm, Ted Zlatanov <t...@lifelogs.com> wrote:
> >
> > > > The problem is that there are NULL values, which are undefined in
> > > > the DBI translation. =3DA0So this
> >
> > > > printf("%s%s", $i ? "," : "", $$ref[$i]);
> >
> > > > should be (for example)
> >
> > > > printf("%s%s", $i ? "," : "", $$ref[$i]||'NULL');
> >
> > > This would be a useful tidbit to add to the documentation. =A0I
> > > hadn't expected a mature library like DBI to behave like this.
> >
> > This is not DBI behavior. =A0It is Perl behavior when undefined valued
> > are encountered. =A0It is documented, just not in the DBI docs. =A0It
> > is n=
> ot
> > reasonable to document every non-DBI problem that one may encounter
> > when using DBI in the DBI docs.
> >
> But null values in SQL are not the same thing as undefined or
> uninitialized values in any other language I know.
There isn't a built-in map function like Perl's in any other language I
know, either. If you want to use another language, use it. If you want to
use Perl, use Perl.
> In any RDBMS I
> have worked with, null is a legitimate value that can be given to a
> specific column in a specific row,
No duh. The question is how to represent those values when the data is
*not* in the RDBMS, but in the language you are using to talk to the RDBMS.
> and it has a very specific meaning
> in a database. Any SQL programmer knows how to handle nulls, what can
> and can not be done with them, &c.
There is plenty of empirical evidence that this is not the case.
> That is very different from
> programming errors where a variable has been defined and then used
> before it has been given a value. So I maintain this IS a DBI issue,
> and there ought to be functionality provided within DBI to handle the
> processing of recordsets, including printing them, that can handle
> null values in a rational manner without generating spurious
> warnings.
There are. You have failed to use them.
> At a minimum the DBI documentation ought to say somethng
> about users needing to implement their own processing to handle null
> values when that is not available.
The DBI docs say, several time, that it translates NULL to undef. It says
what it does, it does what it says.
> The real error here is that, if I
> am to believe Ted, that nulls are treated as undefined in the DBI
> translation, and this is plain wrong. On the daatabase side, nulls
> have a specific meaning (and as you well said, further on, that
> meaning is different from that of an empty string), and DBI ought to
> at least provide a means of handling them correctly from the
> perspective of a database programmer.
I am a database programmer and it handles them correctly from my
perspective.
> The mistake here is to assume this is a perl issue. Perl, like Java
> and C++ and FORTRAN and a host of other programming languages, is
> Turing complete, so anything that can be done in any one of them can
> in principle be done in any of the others. Surely you know that JDBC
> is to Java as DBI is to Perl. What we are talking about here is
> specificlly a database interface issue, and so the relevant aspect of
> perl programming that applies here is the use of DBI. I know how to
> deal with nulls when using JDBC.
Kudos to you. Either learn how to handle them in DBI just like you learned
to use JDBC, or don't use DBI.
...
> >
> > In mysql, a null string and an empty string are two different things.
> > Should both of them be converted to 'N/A', or just the null?
> >
> No, and I must emphasize that in the occassions where I changed the
> behaviour, the change was mandated by the meaning of the data and the
> way it was to be used. In the case in question, the only possible
> values are real numbers and null. In some instances in this
> application, the proper way to display the null is to use an empty
> string. In others, the proper way to display it is to use the string
> "N/A". But I could make these changes easily because both the JDBC
> and JSF are well documented, and by examining that documentation to
> see how the relevant classes/libraries handled nulls in particular and
> data in general, it became clear almost immediately what code I had to
> write to obtain the behaviour I required.
So you made the effort to read the JDBC docs, but not the DBI docs. How
is this Perl's fault or DBI's fault? It makes it completely clear how
NULLs are handled. In fact, it even says how to convert them to empty
strings:
(From the docs for DBI v1.58):
Here's how to convert fetched NULLs (undefined values) into empty
strings:
while($row = $sth->fetchrow_arrayref) {
# this is a fast and simple way to deal with nulls:
foreach (@$row) { $_ = '' unless defined }
print "@$row\n";
}
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Thu, 24 Apr 2008 18:50:18 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
Message-Id: <fuqks4.1ek.1@news.isolution.nl>
Ted schreef:
> So I maintain this IS a DBI issue,
> and there ought to be functionality provided within DBI to handle the
> processing of recordsets, including printing them, that can handle
> null values in a rational manner without generating spurious
> warnings.
Troll alert.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Fri, 25 Apr 2008 04:16:31 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
Message-Id: <furm0v.kg.1@news.isolution.nl>
Ted schreef:
> On the matter of undefined, though. Wall et al. say that an undefined
> variable is one that does not presently hold a valid string, numeric
> or reference value. The only way I see that happening is if the
> variable is not initialized.
That you are reading certain phrases in your own way is only natural,
unless after you were told that you got it wrong.
You have been told several times already that in Perl you can undef the
value of a variable, see `perldoc -tf undef`.
undef is the default value (or rather state) of a (scalar) variable.
In Perl a variable can have multiple (internal, cached) values at the
same time, like 3 and "3", for performance reasons.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 24 Apr 2008 00:21:06 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
Message-Id: <SnQPj.1820$XI1.271@edtnps91>
Ted Zlatanov wrote:
> On Wed, 23 Apr 2008 13:40:58 -0700 (PDT) smallpond <smallpond@juno.com> wrote:
>
> s> Each call to fetchrow_arrayref gets a new row, but you
> s> only check numFields once. So your rows don't all have
> s> the same number of fields.
>
> That SELECT SQL query will not return a variable number of fields.
>
> The problem is that there are NULL values, which are undefined in the
> DBI translation. So this
>
> printf("%s%s", $i ? "," : "", $$ref[$i]);
>
> should be (for example)
>
> printf("%s%s", $i ? "," : "", $$ref[$i]||'NULL');
Of course you don't really need printf() for that:
print $i ? ',' : '', $ref->[ $i ] || 'NULL';
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Thu, 24 Apr 2008 11:12:21 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
Message-Id: <48105d09$0$26079$db0fefd9@news.zen.co.uk>
Ted wrote:
> On Apr 23, 7:38 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>> Ted <r.ted.by...@rogers.com> wrote in news:3b842be5-7145-42f6-9f5a-
>> ad1c3a50a...@x35g2000hsb.googlegroups.com:
>>
>>> table is returned. However, The correct output is punctuated about
>>> every 100 lines by hundreds of error messages: "Use of uninitialized
>>> value in printf at k:/MerchantData/MSDB.pl line 34." That is the
>>> printf in the for loop within the while loop. This increases the
>>> number of lines of output from precisely 529 to more than 1800! That
>>> is almost three times as much garbage as there is real data.
>> 1. Those are warnings, not errors. The difference matters.
>>
> Yes, but treating warnings as if they're errors alows one to develop
> more robust code.
That may be generally true of Perl too but, with Perl, there are a few
circumstances where it may be best to suppress specific warnings for a
limited scope.
I occasionally use @SuppressWarnings("unchecked") in Java because some
Java core classes are not generified or because type-erasure renders
some type-casts uncheckable at runtime. Treating those as errors (or as
bugs in Eclipse) would be wrong IMO.
Notwithstanding the above, I find it unhelpful to adopt Java (or C++)
habits or principles when writing Perl.
>> 2. By default, warnings go to STDERR.
>
> Right. But the trick is to figure out how to separate STDOUT from
> STDERR within Emacs. Doing so on the commandline is trivial using
> redirection, but within Emacs? That may be an annoyance I'll have to
> live with for now.
I use Perl, I don't use Emacs. I think this problem is an Emacs problem
and shouldn't be muddled together with discussion here of your concerns
about Perl DBI/DBD.
--
RGB
------------------------------
Date: Thu, 24 Apr 2008 17:48:31 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
Message-Id: <4810b9df$0$32048$da0feed9@news.zen.co.uk>
Ted wrote:
> On Apr 24, 10:56 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>>
>> I saw your discussion with the others, it covered all the bases. I
>> agree with Abigail (unsurprisingly), but I also think the current DBI
>> approach is the best compromise between ideology and pragmatism.
>>
> She is a gem, isn't she?!!
>
He (Abigail) may well be a gem.
--
RGB
------------------------------
Date: Fri, 25 Apr 2008 00:31:55 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: use of DBI; I am getting multiple error messages mixed in with ?the correct output.
Message-Id: <pan.2008.04.24.22.31.54@rtij.nl.invlalid>
On Thu, 24 Apr 2008 14:10:08 +0000, Ben Bullock wrote:
> Ted <r.ted.byers@rogers.com> wrote:
>
>>> Try running the following script to clarify what this means:
>>>
>>> #!/usr/bin/perl
>>> use warnings;
>>> use strict;
>>> my $a;
>>> my $b = "";
>>> print "a is defined\n" if defined($a); print "b is defined\n" if
>>> defined($b);
>>>
>>> Here $b is a "real null string" and $a is undefined.
>
> Excuse me, this should say '$b is a "defined null string"' not "real".
No, $b is an empty string. Certainly not a null string. There is no such
thing as a null string in perl. C++ has a null string concept IIRC, but
Java and C don't, they allow the variable to be set to NULL, which in
perl is setting it to undef.
M4
------------------------------
Date: Wed, 23 Apr 2008 18:57:31 -0700 (PDT)
From: cca.johnson@gmail.com
Subject: Using a file's modification date in the filename
Message-Id: <34518a8b-abbb-4b08-aed3-b359bfbe29bc@y38g2000hsy.googlegroups.com>
I want to be able to rename a file and prepend the file's modification
date at the front of the file. For example:
with a file named testme.txt and a modification date of April 1, 2006,
I want the renamed file to be named 20060401-testme.txt
What I can do is get the modification date using ctime, but it I can't
figure out how to format the output. I am able to format the date the
way I like using strftime. Here is some sample code which shows the
output I do and do not want:
#!/usr/bin/perl -w
use strict ;
use warnings ;
use POSIX qw(strftime);
# print today's date YYYYMMDD:
my $now_time = strftime "%Y%m%d", localtime;
print "I want it formatted this way:\n$now_time\n";
# print the modified date of file:
use File::stat;
use Time::localtime;
my $file = "testme.txt";
my $timestamp = ctime(stat($file)->mtime);
print "...but not this way:\n $timestamp\n";
Any assistance would be appreciated,
------------------------------
Date: Thu, 24 Apr 2008 02:23:38 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Using a file's modification date in the filename
Message-Id: <rerv041l3mb08vm1ga2qkim0915id8trbk@4ax.com>
cca.johnson@gmail.com wrote:
>I want to be able to rename a file and prepend the file's modification
>date at the front of the file. For example:
>with a file named testme.txt and a modification date of April 1, 2006,
>I want the renamed file to be named 20060401-testme.txt
>
>What I can do is get the modification date using ctime, but it I can't
>figure out how to format the output.
It seems like Date::Formatter will probably do what you are looking for.
jue
------------------------------
Date: 24 Apr 2008 02:25:26 GMT
From: xhoster@gmail.com
Subject: Re: Using a file's modification date in the filename
Message-Id: <20080423222530.247$G9@newsreader.com>
cca.johnson@gmail.com wrote:
> I want to be able to rename a file and prepend the file's modification
> date at the front of the file. For example:
> with a file named testme.txt and a modification date of April 1, 2006,
> I want the renamed file to be named 20060401-testme.txt
>
> What I can do is get the modification date using ctime, but it I can't
> figure out how to format the output. I am able to format the date the
> way I like using strftime. Here is some sample code which shows the
> output I do and do not want:
>
> #!/usr/bin/perl -w
> use strict ;
> use warnings ;
> use POSIX qw(strftime);
>
> # print today's date YYYYMMDD:
> my $now_time = strftime "%Y%m%d", localtime;
> print "I want it formatted this way:\n$now_time\n";
mtime and time both use seconds since the epoch, so
it should work the same way if you just give localtime the results of
mtime instead of letting it default to using time.
my $now_time = strftime "%Y%m%d", localtime(stat($file)->mtime);
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Wed, 23 Apr 2008 20:41:20 -0700 (PDT)
From: cca.johnson@gmail.com
Subject: Re: Using a file's modification date in the filename
Message-Id: <f9250bd1-8dd7-4e7e-8fb1-d173c7fd32fe@34g2000hsf.googlegroups.com>
On Apr 23, 9:25 pm, xhos...@gmail.com wrote:
> cca.john...@gmail.com wrote:
> > I want to be able to rename a file and prepend the file's modification
> > date at the front of the file. For example:
> > with a file named testme.txt and a modification date of April 1, 2006,
> > I want the renamed file to be named 20060401-testme.txt
>
> > What I can do is get the modification date using ctime, but it I can't
> > figure out how to format the output. I am able to format the date the
> > way I like using strftime. Here is some sample code which shows the
> > output I do and do not want:
>
> > #!/usr/bin/perl -w
> > use strict ;
> > use warnings ;
> > use POSIX qw(strftime);
>
> > # print today's date YYYYMMDD:
> > my $now_time = strftime "%Y%m%d", localtime;
> > print "I want it formatted this way:\n$now_time\n";
>
> mtime and time both use seconds since the epoch, so
> it should work the same way if you just give localtime the results of
> mtime instead of letting it default to using time.
>
> my $now_time = strftime "%Y%m%d", localtime(stat($file)->mtime);
>
> Xho
After I removed use Time::localtime, this worked without error. My
guess is that there is a conflict between POSIX qw(strftime)and
Time::localtime. Here is what I have:
#!/usr/bin/perl -w
use strict ;
use warnings ;
use POSIX qw(strftime);
use File::Copy;
use File::stat;
# print today's date YYYYMMDD:
my $now_time = strftime "%Y%m%d", localtime;
print "I want it formatted this way:\n$now_time\n";
# print the modified date of file:
my $file = "testme.txt";
my $file_time = strftime "%Y%m%d", localtime(stat($file)->mtime);
print "file $file will be renamed $file_time-$file\n";
copy("$file", "$file_time-$file") or die "can't copy file: $!";
Thank you,
------------------------------
Date: Thu, 24 Apr 2008 01:34:09 -0500
From: "Gerry Ford" <gerry@nowhere.ford>
Subject: Re: Using a file's modification date in the filename
Message-Id: <1209018421_3099@news.newsgroups.com>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:rerv041l3mb08vm1ga2qkim0915id8trbk@4ax.com...
> cca.johnson@gmail.com wrote:
>>I want to be able to rename a file and prepend the file's modification
>>date at the front of the file. For example:
>>with a file named testme.txt and a modification date of April 1, 2006,
>>I want the renamed file to be named 20060401-testme.txt
>>
>>What I can do is get the modification date using ctime, but it I can't
>>figure out how to format the output.
>
> It seems like Date::Formatter will probably do what you are looking for.
http://search.cpan.org/~stevan/Date-Formatter-0.09/lib/Date/Formatter.pm
I thought I'd chase after it, as if wanting to install the module myself.
I'm disappointed that ActiveState's PPM rarely has the modules I'm looking
for. Maybe I don't know how to look. The authors included this caveat:
For serious date/time involved work, skip my module and go straight to the
DateTime project at L<http://datetime.perl.org>. Don't even waste your time
with anything else.
, and this link to the larger question in Perl:
http://www.perl.com/pub/a/2003/03/13/datetime.html
--
"Life in Lubbock, Texas, taught me two things: One is that God loves you
and you're going to burn in hell. The other is that sex is the most
awful, filthy thing on earth and you should save it for someone you love."
~~ Butch Hancock
------------------------------
Date: Wed, 23 Apr 2008 14:09:04 +0200
From: "M.O.B. i L." <mikaelb@df.lth.se>
Subject: Re: WWW::Mechanize doesn't always follow_link(text
Message-Id: <fun8t0$bfo$1@news.lth.se>
John Bokma wrote:
> "M.O.B. i L." <mikaelb@df.lth.se> wrote:
>
>> I'm using WWW::Mechanize 1.34 and have a problem.
>> This doesn't work:
>> $agent->follow_link(text => 'Edit Librarians', n => 1);
>> It doesn't work in the sense that the link isn't followed and the $agent
>> is still on the same page. Is there a bug in my code or is there a known
>> bug in WWW::Mechanize. I've tried to change to space but that
>> didn't work.
>>
>> This works:
>> $agent->follow_link(url_regex => qr/librarians/, n => 1);
>>
>> The corresponding XHTML code is:
>> <a href="mkbAdmin?func=librarians&lang=en">Edit Librarians</a>
>>
>> I want it to work since I use HTTP::Recorder to generate the code
>> automatically as I surf using a proxy and it generates code of the type
>> that doesn't work.
>>
>> This works:
>> $agent->follow_link(text => 'Logout', n => 1);
>>
>> By the way HTTP::Recorder actually generates:
>> $agent->follow_link(text => 'Edit Librarians', n => '1');
>
> HTML::TreeBuilder, or a module it's using, returns as a single
> character, it might be that you have to
> use the code instead.
>
> Comment on http://johnbokma.com/perl/search-term-suggestion-tool.html
> says: ( , stored as char 225)
>
> So you might want to try: "Edit\xe1Librarians".
>
> Wild guess.
>
Thanks! But it should be \xa0. First I tried matching with regular
expressions and that worked using . (dot) for the unknown character. I
then found this page about
<http://www.w3.org/International/questions/qa-escapes> where it says:
"An example of an ambiguous character is 00A0: NO-BREAK SPACE. This type
of space prevents line breaking, but it looks just like any other space
when used as a character. Using (or  ) makes it quite clear
where such spaces appear in the text.".
So this works:
$agent->follow_link(text => "Edit\xa0Librarians", n => 1);
------------------------------
Date: 23 Apr 2008 16:07:27 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: WWW::Mechanize doesn't always follow_link(text
Message-Id: <Xns9A89712A79C0Dcastleamber@130.133.1.4>
"M.O.B. i L." <mikaelb@df.lth.se> wrote:
> John Bokma wrote:
[..]
>> HTML::TreeBuilder, or a module it's using, returns as a single
>> character, it might be that you have to
>> use the code instead.
>>
>> Comment on http://johnbokma.com/perl/search-term-suggestion-tool.html
>> says: ( , stored as char 225)
>>
>> So you might want to try: "Edit\xe1Librarians".
>>
>> Wild guess.
>>
> Thanks! But it should be \xa0.
Yeah, but HTML::TreeBuilder returns it as 225 :-D.
[..]
> So this works:
> $agent->follow_link(text => "Edit\xa0Librarians", n => 1);
Glad my post was able to help you in the right way.
--
John
http://johnbokma.com/perl/
------------------------------
Date: Thu, 24 Apr 2008 19:17:55 +0200
From: "M.O.B. i L." <mikaelb@df.lth.se>
Subject: Re: WWW::Mechanize doesn't always follow_link(text
Message-Id: <fuqfc1$7g3$1@news.lth.se>
M.O.B. i L. wrote:
> Thanks! But it should be \xa0. First I tried matching with regular
> expressions and that worked using . (dot) for the unknown character. I
> then found this page about
> <http://www.w3.org/International/questions/qa-escapes> where it says:
> "An example of an ambiguous character is 00A0: NO-BREAK SPACE. This type
> of space prevents line breaking, but it looks just like any other space
> when used as a character. Using (or  ) makes it quite clear
> where such spaces appear in the text.".
>
> So this works:
> $agent->follow_link(text => "Edit\xa0Librarians", n => 1);
I add that I have developed these command lines to convert back and forth:
sed -i '/ /s/ /\\xa0/g;/\\xa0/s/'\''/"/g' MKBTest.pl
sed -i '/\\xa0/s/\\xa0/\ /g;/ /s/"/'\''/g' MKBTest.pl
------------------------------
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 1485
***************************************