[18926] in Perl-Users-Digest
Perl-Users Digest, Issue: 1121 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 12 18:10:55 2001
Date: Tue, 12 Jun 2001 15:10:21 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <992383821-v10-i1121@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 12 Jun 2001 Volume: 10 Number: 1121
Today's topics:
Re: Mysql connect specifying port <pne-news-20010612@newton.digitalspace.net>
Re: MYSQL DBI: $sth->execute($variable) is not working ctcgag@hotmail.com
Re: New word <pne-news-20010612@newton.digitalspace.net>
Re: New word <gamtci@mpinet.net>
Re: New word <krahnj@acm.org>
Re: New word <gamtci@mpinet.net>
Re: Perl "html Tables" <ren@tivoli.com>
perl script runs twice (chris)
Re: perl script runs twice <hillr@ugs.com>
Removing ^M characters <thanh.q.lam@alcatel.com>
Re: Removing ^M characters <todd@designsouth.net>
search script patrick@xenic.nl
Re: Simplest code to test if web site is up? <comdog@panix.com>
Re: sorting a hash on part of its value? <m.grimshaw@salford.ac.uk>
Re: sorting a hash on part of its value? <krahnj@acm.org>
Re: sorting a hash on part of its value? <c_clarkson@hotmail.com>
Re: sorting a hash on part of its value? <m.grimshaw@salford.ac.uk>
Re: sorting a hash on part of its value? <ren@tivoli.com>
sorting a list of files from a directory (Zsa Zsa)
Re: sorting a list of files from a directory <krahnj@acm.org>
Re: Table/Cell formatting with CGI.pm <c_clarkson@hotmail.com>
Re: Table/Cell formatting with CGI.pm (E.Chang)
Re: Table/Cell formatting with CGI.pm (Craig Berry)
Re: Vars, vars, vars... <jblakey@frogboy.net>
Re: What is ${'string'} ? <todd@designsouth.net>
Re: Why two lists instead of HOH? (Sweth Chandramouli)
Re: Why two lists instead of HOH? <mjcarman@home.com>
Re: Why two lists instead of HOH? (Sweth Chandramouli)
Re: Why two lists instead of HOH? <ren@tivoli.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 12 Jun 2001 21:04:57 +0200
From: Philip Newton <pne-news-20010612@newton.digitalspace.net>
Subject: Re: Mysql connect specifying port
Message-Id: <ioocit4fvac9druspf8jh02sn34iqdffpv@4ax.com>
On 12 Jun 2001 13:02:31 -0400, Vinny Murphy <vmurphy@Cisco.Com> wrote:
> From 'perldoc DBI'
Your quote is not terribly helpful since you forgot the next few lines
after it:
: There is *no standard* for the text following the driver
: name. Each driver is free to use whatever syntax it wants.
So the correct syntax depends on the database driver. DBD::mysql, in
this case, would have been better. Knowing that "at least one database
driver uses syntax X" is not, in general, a helpful thing to know.
: You must consult
: the documentation for the drivers you are using for a
: description of the syntax they require.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 12 Jun 2001 21:34:08 GMT
From: ctcgag@hotmail.com
Subject: Re: MYSQL DBI: $sth->execute($variable) is not working.
Message-Id: <20010612173407.665$wt@newsreader.com>
frm@writeme.com (Frank M) wrote:
> $sortby = $ENV{'QUERY_STRING'};
> #Column given by the user (like Employees.FirstName)
Er, are you sure that $sortby contains what you think it contains?
Trying printing it back to the web browser.
>
> my $sql_statement = "SELECT Employees.FirstName, Employees.LastName,
> PhoneNumbers.*
> FROM Employees, PhoneNumbers
> WHERE Employees.UserName = PhoneNumbers.UserName
> ORDER BY ?";
>
> my $sth = $dbh->prepare($sql_statement);
> $sth->execute($sortby) or die "Can't execute SQL statement :
> $dbh->errstr";
>
> The Query gets the info from the database, but the sort method does
> not work. I am not sure if $sortby is even being passed to the ORDER
> BY ? at all. What could be causing this?
Passing a parameter by ? automatically quotes it to give it as a string.
If you tell mysql to order by a string which happens to be a column
name, it will sort by the column. But if you pass it a string that doesn't
correspond to any column name, it will silently return unsorted data.
(As opposed to telling mysql to order by a (non-quoted) non-existent
column, where it will complain that the column doesn't exist)
posted and mailed
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet for the Web
------------------------------
Date: Tue, 12 Jun 2001 21:27:29 +0200
From: Philip Newton <pne-news-20010612@newton.digitalspace.net>
Subject: Re: New word
Message-Id: <2rqcitktnnsu0qg9p4v97phdqghpnljbkk@4ax.com>
On Tue, 12 Jun 2001 15:29:20 GMT, Gary <gamtci@mpinet.net> wrote:
> Since having used require and use, I find that a simpler merge
> would be handy, particularly if all one wanted to do was have a
> Perl script brought it to the currently being read/compiled one
> as though the merged-in file were part of the original file and
> at the location merge was encountered.
If you have a C preprocessor handy, you may be able to use that by
calling Perl with the -P switch, which feeds the script through cpp.
Then you can use #include directives. (You'll also need to be more
careful with Perl comments on lines by themselves, however.)
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Tue, 12 Jun 2001 19:53:45 GMT
From: Gary <gamtci@mpinet.net>
Subject: Re: New word
Message-Id: <3B267399.C69@mpinet.net>
I don't think my C preprocessor is going to like what it sees
in here. Aren't statements like $_[0], \$myvar or <=> going to
lead the preprocessor to error out? Or are you saying I should
write a massive set of define macros? I'm unclear on how I can
use the preprocessor, I guess.
I may be long on ignorance on this, but it seems more and more
like a true "include" would be an excellent addition.
------------------------------
Date: Tue, 12 Jun 2001 20:47:49 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: New word
Message-Id: <3B26801C.8EC3320@acm.org>
Gary wrote:
>
> I don't think my C preprocessor is going to like what it sees
> in here. Aren't statements like $_[0], \$myvar or <=> going to
> lead the preprocessor to error out? Or are you saying I should
> write a massive set of define macros? I'm unclear on how I can
> use the preprocessor, I guess.
The C preprocessor just does test substitution. (I know it does a bit
more but for Gary's purposes this is correct)
#define XXX yyy
is the same as (in perl)
s/XXX/yyy/g;
#include "filename.pl"
substitutes this line in the current file for the contents of
filename.pl
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 12 Jun 2001 21:07:31 GMT
From: Gary <gamtci@mpinet.net>
Subject: Re: New word
Message-Id: <3B2684E1.7BCA@mpinet.net>
OK, well, I've never tried to use (abuse?) my preprocessor like
this before. I know it's a substitution program, but I never
really gave much thought as to whether it might barf on bizarre
(to C) syntax. I now agree it can be used to do this. However,
the comment issue (namely #) is sure to cause some problems.
Restructuring of the Perl file would probably overcome this.
Am I to conclude adding a Perl include is a bad idea?
------------------------------
Date: 12 Jun 2001 14:56:51 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Perl "html Tables"
Message-Id: <m3hexllbek.fsf@dhcp9-173.support.tivoli.com>
On Tue, 12 Jun 2001, martin.cassidy@uk.sun.com wrote:
> Hi all,
>
> I am trying to write a web page where i ping, arp and rup some
> machines and return the data to a page in table format. My problem
> is when i run the ping command i get the info ok in column 1 but i
> cannot get the arp and rup data to display in the correct columns.
> Any Ideas ! My code is below :-
>
[Perl & HTML snipped for brevity]
>
> I am not sure if the HTML is correct, infact is probably wrong for
> what i want to do, all i want is the perl to read a list of machines
> and ping arp and rup each of them.
The two biggest problems I see are:
1) You're not even calling arp or rup.
2) You're not parsing the output of ping (or the others, presumably),
so it doesn't really get formatted. You might be able to get
around this, but that would require outputting the appropriate
tags before and between each system call. And watch out for IO
buffering!
Based on this snippet:
> print "<TR><TR><TH>$key<TD>$formdata{key}\n\n";
>
> system ("ping $key.uk")}
You might want something like
print "<TD>";
system "ping $key.uk";
print "</TD><TD>";
system "arp -a $key.uk";
print "</TD><TD>";
system "rup $key.uk";
print "</TD>";
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 12 Jun 2001 13:32:40 -0700
From: ccc2@lehigh.edu (chris)
Subject: perl script runs twice
Message-Id: <38a0c234.0106121232.6411ce23@posting.google.com>
I have a perl script acting as a CGI, and when I run it in IE 5.5, it
runs twice for no discernable reason. It works fine in IE 5.0, does
anybody have any idea why 5.5 could be making it run twice, and how I
could make it stop?
Thanks,
Chris
------------------------------
Date: Tue, 12 Jun 2001 13:52:58 -0700
From: Ron Hill <hillr@ugs.com>
Subject: Re: perl script runs twice
Message-Id: <3B26812A.5BEA5B33@ugs.com>
chris wrote:
> I have a perl script acting as a CGI, and when I run it in IE 5.5, it
> runs twice for no discernable reason. It works fine in IE 5.0, does
> anybody have any idea why 5.5 could be making it run twice, and how I
> could make it stop?
> Thanks,
> Chris
http://perl.plover.com/Questions4.html
------------------------------
Date: Tue, 12 Jun 2001 15:46:05 -0400
From: Thanh Q Lam <thanh.q.lam@alcatel.com>
Subject: Removing ^M characters
Message-Id: <3B26717D.BE551C2E@alcatel.com>
Does anyone know how to remove the "^M" characters at the end of each line which without
removing uppercase M that may have in the same line in perl?
Examples:
This is a book^M
That is a Mango^M
If I use tr -d in unix which will remove all "M"
Result:
This is a book
That is a ango
Your help will be very appreciated.
-Thanh
------------------------------
Date: Tue, 12 Jun 2001 20:01:47 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: Removing ^M characters
Message-Id: <LyuV6.140953$I5.37896511@news1.rdc1.tn.home.com>
"Thanh Q Lam" <thanh.q.lam@alcatel.com> wrote in message
news:3B26717D.BE551C2E@alcatel.com...
> Does anyone know how to remove the "^M" characters at the end of each line
which without
> removing uppercase M that may have in the same line in perl?
>
> Examples:
> This is a book^M
> That is a Mango^M
>
> If I use tr -d in unix which will remove all "M"
>
> Result:
> This is a book
> That is a ango
>
>
> Your help will be very appreciated.
"\cM" is a control-M
------------------------------
Date: Tue, 12 Jun 2001 21:53:56 GMT
From: patrick@xenic.nl
Subject: search script
Message-Id: <3b268ed0.37804671@news.freeler.nl>
Hi,
Can anyone help me with a script that search a file (txt) from a user input in
.html format.
Not like the most search scripts that shows filenames etc, just like:
give input: blah
read .txt file
give output:
Blah found etc. ...
.txt file looks like:
name, name1, name2, name3 etc.
Anyone .. Please ?
Regards, Patrick.
------------------------------
Date: Tue, 12 Jun 2001 14:52:56 -0700
From: brian d foy <comdog@panix.com>
Subject: Re: Simplest code to test if web site is up?
Message-Id: <comdog-79999E.14525612062001@news.panix.com>
In article <9g3jpu$pu1$1@dinkel.civ.utwente.nl>, "Willem"
<usenet@willem.byte.nl> wrote:
> "B Wooster" <b.wooster@usa.net> wrote in message
> news:cb45ebcb.0106111035.34abf2a9@posting.google.com...
> > I've been looking at libwww and it can certainly
> > do what I need to - but is there some very simple
> > Perl code that can check if the web server at a
> > particular site is up?
> >
> > I need this:
> >
> > $site_is_up = &check_site("www.somesite.com");
> Use IO::Socket (std module) and send "HEAD / HTTP/1.0\n\n" to the server. If
> you get a response, it is working :-)
these are the only entries for the simplest code? gees.
use LWP::Simple;
my $url = 'http://www.perl.org';
print "Site is alive\n" if( head( $url ) or get( $url ) );
note that a HEAD request may fail although the site might be
available. some servers don't handle HEAD correctly.
--
brian d foy <comdog@panix.com>
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html
------------------------------
Date: Tue, 12 Jun 2001 19:25:37 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: sorting a hash on part of its value?
Message-Id: <3B265EA1.6E871148@salford.ac.uk>
Andras Malatinszky wrote:
>
> Mark Grimshaw wrote:
>
> > Hi all,
> >
> > I have what I suspect is a highly inefficient algorithm (due to the
> > number of loops I have) for sorting a hash based on _part_ of its value
> > string. (perldoc -q sort only demonstrates how to sort a hash on all of
> > its value string.) What I have works but is slow. I would appreciate
> > any help in making the alogorithm more efficient/quicker.
> >
> > The value string of my DB_File db is delimited by '¬' and among other
> > data, contains the UNIX time of when a user last logged on (using a
> > bulletin board I've written).
> >
> > A further complication is that this UNIX time may be the same across
> > different key : value pairs (if people happen to have logged on in the
> > same second).
> >
> > Additionally, I need to keep the rest of the hash value tied to its UNIX
> > time so that I can display, for example, who it was who logged in at
> > that time.
> >
> > example:
> >
> > key : status¬email¬numposts¬UNIX time¬etc.¬etc.¬etc. although my actual
> > UNIX time is in index 10.
> >
> > I need to sort the hash on UNIX time which may be the same as another
> > UNIX time in another key : value pair.
> >
> > Here's the code I'm using:
> >
> > foreach $key(keys %USER)
> > {
> > @string = split(/¬/, $USER{$key});
> > if($string[10] ne 'null')
> > {
> > push(@time, $string[10]);
> > }
> > else
> > {
> > push(@reprobates, $key); # these will be
> > displayed last - order unimportant.
> > }
> > }
> > @time = reverse sort {$a <=> $b} @time; # to get last login time
> > first.
> > # highly inefficient sort algorithm - needs sorting ;) some time
> > foreach(@time)
> > {
> > $time = $_;
> > @names = keys %USER; # keys are the names of users which
> > will be $profile'ised
> > BACK2: foreach(@names)
> > {
> > $name = $_;
> > foreach(@done)
> > {
> > next BACK2 if($name eq $_); #
> > already done this one
> > }
> > @string = split(/¬/, $USER{$name});
> > # doesn't matter if $time happens to be from another @string (another
> > key:value pair)
> > # as it's simply the login time and if 2 people happen to have logged in
> > at the same time, who cares
> > # which is displayed first.
> > if($string[10] eq $time)
> > {
> > # check for spaces in usernames
> > $profile = $name;
> > if($profile =~ / /)
> > {
> > $profile =~ s/ /%20/g;
> > }
> > push(@done, $name);
> > last;
> > }
> > }
> > $time = q_time_of_post($time); # pulled from an external
> > module - simply formats $time
> > # into readable format
> > print "<LI><A
> > HREF=\"register.cgi?view=$profile\">$name</A>,
> > last seen: $time";
> > }
>
> Try this: I think
>
> sort {(split(/¬/, $USER{$b})[10] <=> (split(/¬/, $USER{$a})[10] } keys %USER
>
> would give you a list of the keys in %USER sorted descending by time.
I've been trying to use something like that. Using your version as:
# line 394
@names = sort {(split(/¬/, $USER{$b})[10] <=> (split(/¬/,
$USER{$a})[10] } keys %USER;
I get:
Can't use subscript on split at ./admin.cgi line 394, near "10]"
Can't use subscript on split at ./admin.cgi line 394, near "10]"
syntax error at ./admin.cgi line 394, near "] }"
Which is more or less what I've been getting each time I've tried it.
------------------------------
Date: Tue, 12 Jun 2001 18:50:10 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: sorting a hash on part of its value?
Message-Id: <3B266461.E78426F0@acm.org>
Mark Grimshaw wrote:
>
> Andras Malatinszky wrote:
> >
> > Try this: I think
> >
> > sort {(split(/¬/, $USER{$b})[10] <=> (split(/¬/, $USER{$a})[10] } keys %USER
> >
> > would give you a list of the keys in %USER sorted descending by time.
>
> I've been trying to use something like that. Using your version as:
> # line 394
> @names = sort {(split(/¬/, $USER{$b})[10] <=> (split(/¬/,
> $USER{$a})[10] } keys %USER;
>
> I get:
> Can't use subscript on split at ./admin.cgi line 394, near "10]"
> Can't use subscript on split at ./admin.cgi line 394, near "10]"
> syntax error at ./admin.cgi line 394, near "] }"
>
> Which is more or less what I've been getting each time I've tried it.
The brackets aren't balanced. :)
sort { (split /¬/, $USER{$b})[10] <=> (split /¬/, $USER{$a})[10] } keys
%USER
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 12 Jun 2001 12:42:31 -0500
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: sorting a hash on part of its value?
Message-Id: <03BDEAFD8DC4B311.57EFD5609600AA61.882B932B472EDC5E@lp.airnews.net>
Mark Grimshaw <m.grimshaw@salford.ac.uk> wrote
: Hi all,
:
: I have what I suspect is a highly inefficient algorithm
: (due to the number of loops I have) for sorting a hash
: based on _part_ of its value string. (perldoc -q sort
: only demonstrates how to sort a hash on all of its
: value string.) What I have works but is slow. I would
: appreciate any help in making the alogorithm more
: efficient/quicker.
:
: The value string of my DB_File db is delimited by '¬'
: and among other data, contains the UNIX time of when
: a user last logged on (using a bulletin board I've
: written).
:
: A further complication is that this UNIX time may be
: the same across different key : value pairs (if
: people happen to have logged on in the same second).
:
: Additionally, I need to keep the rest of the hash
: value tied to its UNIX time so that I can display,
: for example, who it was who logged in at that time.
:
: example:
:
: key : status¬email¬numposts¬UNIX time¬etc.¬etc.¬etc.
: although my actual UNIX time is in index 10.
:
: I need to sort the hash on UNIX time which may be
: the same as another UNIX time in another
: key : value pair.
:
: Here's the code I'm using:
[snip]
: @string = split(/¬/, $USER{$key});
: if($string[10] ne 'null')
: {
: push(@time, $string[10]);
[snip]
: foreach(@time)
: {
[snip]
: $time = $_;
: $time = q_time_of_post($time); # pulled from an external
:[snip]
: $profile = $name;
: if($profile =~ / /)
: {
: $profile =~ s/ /%20/g;
: }
: print "<LI><A HREF=\"register.cgi?view=$profile\">",
: "$name</A>, last seen: $time";
: }
Since your only interested in the $name, $time
and $profile, why not just create a second hash.
Let's call it %time and use the same keys as %USER.
Let's use %nulls to hold the null times.
my %time;
my %nulls;
foreach my $name (keys %USER) {
my $profile = $name;
$profile =~ s/ /%20/g;
my $time = (split /¬/, $USER{$name})[10];
if ( $time eq 'null' ) {
$nulls{$name} = [$time, $profile];
} else {
$time{$name} = [$time, $profile];
}
}
The time is in $time{$name}[0] and the profile
is in $time{$name}[1]. To sort the names by time:
my @reverse_sorted_by_time =
sort {$time{$b}[0] <=> $time{$a}[0]} keys %time;
Then we can print the list items:
foreach my $name (@reverse_sorted_by_time) {
print
qq(<LI><A HREF="register.cgi?view=$time{$name}[1]">),
qq($name</A>, last seen: $time{$name}[0]);
}
And the nulls:
foreach my $name (sort keys %nulls) {
print
qq(<LI><A HREF="register.cgi?view=$nulls{$name}[1]">),
qq($name</A>, never seen again.);
}
HTH,
Charles K. Clarkson
Clarkson Energy Homes, Inc.
Nobody owes anyone else a living.
------------------------------
Date: Tue, 12 Jun 2001 20:23:16 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: sorting a hash on part of its value?
Message-Id: <3B266C24.F8347A79@salford.ac.uk>
"John W. Krahn" wrote:
>
> Mark Grimshaw wrote:
> >
> > Andras Malatinszky wrote:
> > >
> > > Try this: I think
> > >
> > > sort {(split(/¬/, $USER{$b})[10] <=> (split(/¬/, $USER{$a})[10] } keys %USER
> > >
> > > would give you a list of the keys in %USER sorted descending by time.
> >
> > I've been trying to use something like that. Using your version as:
> > # line 394
> > @names = sort {(split(/¬/, $USER{$b})[10] <=> (split(/¬/,
> > $USER{$a})[10] } keys %USER;
> >
> > I get:
> > Can't use subscript on split at ./admin.cgi line 394, near "10]"
> > Can't use subscript on split at ./admin.cgi line 394, near "10]"
> > syntax error at ./admin.cgi line 394, near "] }"
> >
> > Which is more or less what I've been getting each time I've tried it.
>
> The brackets aren't balanced. :)
>
> sort { (split /¬/, $USER{$b})[10] <=> (split /¬/, $USER{$a})[10] } keys
> %USER
Brilliant! - thank very much all. A vast improvement in speed and less
lines of code!
------------------------------
Date: 12 Jun 2001 14:11:21 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: sorting a hash on part of its value?
Message-Id: <m3u21lldie.fsf@dhcp9-173.support.tivoli.com>
On Tue, 12 Jun 2001, m.grimshaw@salford.ac.uk wrote:
> @names = sort {(split(/¬/, $USER{$b})[10] <=> (split(/¬/,
> $USER{$a})[10] } keys %USER;
>
> I get:
> Can't use subscript on split at ./admin.cgi line 394, near "10]"
> Can't use subscript on split at ./admin.cgi line 394, near "10]"
> syntax error at ./admin.cgi line 394, near "] }"
>
> Which is more or less what I've been getting each time I've tried
> it.
You don't have enough parens (neither did the example that you were
given). You can only subscript a split by putting parens around the
entire split:
@names = sort { ( split /¬/, $USER{$b} )[10] <=>
( split /¬/, $USER{$a} )[10] } keys %USER;
If %USER is very big, you'll be better off with a Schwartzian
Transform (or GRT):
@names = map { $_->[1] }
sort { $_->[0] <=> $_->[0] }
map { [ ( split /¬/, $USER{$_} )[10], $_ ] }
keys %USER;
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 12 Jun 2001 19:48:03 GMT
From: iburnedmyfingers@hotmail.com (Zsa Zsa)
Subject: sorting a list of files from a directory
Message-Id: <TluV6.29$SH4.52925@nnrp2.sbc.net>
I am looking for the best way to sort files within a directory for the
purpose of listing.
My ultimate goal is to sort the files in order of last modified (most
recent at top of list).
I developed this:
opendir DIRH, "/path/tofolder" or die "couldn't open: $!";
foreach (sort { -M $a <=> -M $b } readdir DIRH) {
$file = $_;
@info = stat ($file);
@date = localtime($info[9]);
$year = sprintf("%d-%d-%d\n",$date[4]+1,$date[3],$date[5]+1900);
$time = "$date[2]:$date[1]";
$lastmodified = "$year $time";
($filename) = $file =~ m!([^/]*)$!;
print "<tr><td><a
href=\"http://www.url.com/$filename\">$filename</a></td><td>$lastmodified
</td></tr>";
}
closedir DIRH or die "couldn't close directory: $!";
which seems to do custom sorts fine, but then the $lastmodified variable
is always 12-31-1969 16:0
so i tried this:
foreach $file (</path/tofolder/*>) {
@info = stat ($file);
@date = localtime($info[9]);
$year = sprintf("%d-%d-%d\n",$date[4]+1,$date[3],$date[5]+1900);
$time = "$date[2]:$date[1]";
$lastmodified = "$year $time";
($filename) = $file =~ m!([^/]*)$!;
print "<tr><td><a
href=\"http://www.url.com/$filename\">$filename</a></td><td>$lastmodified
</td></tr>";
}
which displays the $lastmodified variable as a current date and time, but
I cannot find a way to customize the sort of the list.
I'm pretty new at PERL, so I'm sure I'm missing some simple coding trick
that will solve my problem. Can anyone help?
------------------------------
Date: Tue, 12 Jun 2001 20:51:32 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: sorting a list of files from a directory
Message-Id: <3B2680FA.952A9274@acm.org>
Zsa Zsa wrote:
>
> I am looking for the best way to sort files within a directory for the
> purpose of listing.
> My ultimate goal is to sort the files in order of last modified (most
> recent at top of list).
> I developed this:
>
> opendir DIRH, "/path/tofolder" or die "couldn't open: $!";
> foreach (sort { -M $a <=> -M $b } readdir DIRH) {
This sorts the oldest files first, change to
foreach (sort { -M $b <=> -M $a } readdir DIRH) {
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 12 Jun 2001 10:47:57 -0500
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: Table/Cell formatting with CGI.pm
Message-Id: <E672135FAC331D99.4099647771F09472.44A1964198F1CE1A@lp.airnews.net>
PaAnWa <paanwa@hotmail.com> wrote:
: Hi Mark,
:
: Sorry I was not clear in my post. I am looking
: for modify what I have into CGI.pm formatting.
: Here is what I have:
:
: print "<td><input type='textbox'
I assume you mean TEXT. The only valid types
I know of are:
TEXT, PASSWORD, CHECKBOX, RADIO, SUBMIT,
RESET, BUTTON, FILE, HIDDEN, IMAGE,
TEXTAREA (not supported in all browsers)
: name='Contact_FirstName'value=",
: param('Contact_FirstName'),"></td>";
:
print
td( textfield( -name => 'Contact_FirstName',
-value => param('Contact_FirstName')));
HTH,
Charles K. Clarkson
Clarkson Energy Homes, Inc.
It is not our preferences that cause problems
but our attachment to them.
- Buddha
------------------------------
Date: Tue, 12 Jun 2001 21:07:09 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Table/Cell formatting with CGI.pm
Message-Id: <Xns90BEAEA953996echangnetstormnet@207.106.92.86>
Michael Carman <mjcarman@home.com> wrote in
<3B2638B3.15DAB78A@home.com>:
>"E.Chang" wrote:
>Who said it was? It will be evaluated. (Look more closely, the call
>is outside of double-qoutes.) Syntactically, the OP's code is
>equivilant to this:
>
> print "aaa", f('x'), "bbb";
>
Doh, you're right - too many assorted quotation marks and line wraps
before morning coffee. And I even used the same construction in my
recommended fix.
--
EBC
------------------------------
Date: Tue, 12 Jun 2001 21:19:31 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Table/Cell formatting with CGI.pm
Message-Id: <tid1r35mu8k724@corp.supernews.com>
Charles K. Clarkson (c_clarkson@hotmail.com) wrote:
: print
: td( textfield( -name => 'Contact_FirstName',
: -value => param('Contact_FirstName')));
No need for the explicit -value; CGI.pm defaults to filling in form
elements with their associated param values unless you explicitly override
this behavior.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Magick is the art and science of causing change in conformity
| with Will." - Aleister Crowley
------------------------------
Date: Tue, 12 Jun 2001 14:29:01 -0400
From: Jason Blakey <jblakey@frogboy.net>
Subject: Re: Vars, vars, vars...
Message-Id: <K9tV6.248379$Z2.2867540@nnrp1.uunet.ca>
Jason Blakey wrote:
> Hi,
>
> i'm using "do" to load some variables from a configuration file... and
> i
> want to "use strict" in the calling program (my new SM kick). So, in my
> calling program, i've tried "our", "my", and "local" declarations for
> those variables from the configuration file, but no luck...
>
> Global symbol "$SSH" requires explicit package name at unix line 19.
>
>
> Do i need to disable someting in the strict module? Or what?
>
> Thanks.
> jason
>
>
Actually, i've found the simplist solution - upgrade to a version of perl
that understands the "our" declaration **bonk**bonk**bonk**
Thanks all, and sorry 'bout that...
jason
--
This email from jason blakey - jblakey@frogboy.net - http://www.frogboy.net
" The Luckiest Guy in the World "
------------------------------
Date: Tue, 12 Jun 2001 19:43:14 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: What is ${'string'} ?
Message-Id: <mhuV6.140808$I5.37858595@news1.rdc1.tn.home.com>
<Gordon.Haverland@gov.ab.ca> wrote in message
news:3b26116d.340959040@news.gov.ab.ca...
> As the subject field says, what is ${'some_string'} ?
>
> Would their be any reason why someone would use this, instead of any
> other variable, when their is only 1 unique string used in the entire
> program.
>
Sometimes I use it so I can write things like:
$item = "dog";
print "I have two ${item}s";
# instead of
print "I have two " . $item . "s";
Currently I'm writing a script that interacts with some mySQL tables, two of
which are named "clients" and "consultants." I pass a cookie on login named
'type' and the value is either 'client' or 'consultant'. I write things like
this:
$type = $cgi->cookie('type');
$uid = $cgi->cookie('uid');
$dbh->do(" delete from ${type}s where ${type}_id = '$uid' ");
It's easier and more readable than
$dbh->do(" delete from " . $type . "s where " . $type . "_id = '$uid' ");
-todd
------------------------------
Date: Tue, 12 Jun 2001 19:24:32 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Why two lists instead of HOH?
Message-Id: <Q%tV6.75490$G5.16103268@news1.rdc1.md.home.com>
In article <3B24C7CA.8892E671@statesman.com>,
Tim Schmelter <tschmelter@statesman.com> wrote:
>No, but you could use
>
>my %fields = (
> firstname => { label=>'first name', max_size=>20, msg_index=>1,
>sort_index=>10 },
> middle => { label=>'middle name', max_size=>20, msg_index=>1,
>sort_index=>20 },
> lastname => { label=>'last name', max_size=>30, msg_index=>0,
>sort_index=>30 },
> password => { label=>'password', max_size=>20, msg_index=>0,
>sort_index=>40 },
>);
>
>and
>
>#UNTESTED
>for my $fieldname (sort { $fields{$a}->{sort_index} <=>
>$fields{$b}->{sort_index} } keys %fields) {
> # Do something
>}
I've been debating this myself recently. A lot of my
code nowadays seems to have snippets like
for my $key (indexsort %some_hash) {
where indexsort is
sub indexsort {
my ($hash_ref) = @_;
if ('HASH' ne ref ($hash_ref)) {
croak ("indexsort requires hash reference as argument!")
} else {
return (sort {
$$hash_ref{$a}{'sortkey'} <=> $$hash_ref{$b}{'sortkey'}
} keys %$hash_ref)
};
};
and %some_hash is constructed like
%some_hash = (
item1 => {
sortkey => 1
,text => "some text"
}
,item2 => {
sortkey => 2
,text => "other text"
}
);
. It's a mixed bag, though; every time I want to reorder
%some_hash, I have to manually renumber all of the sort keys between the
old and new positions of the moved item. I'm seriously leaning towards
switching to the hash+array method, plus a validation sub that runs after
both are defined to make sure that every item in the hash has an entry in
the array and vice versa.
I'd love to see other people's solutions to this problem.
-- Sweth.
--
Sweth Chandramouli ; <sweth+perl@gwu.edu>
------------------------------
Date: Tue, 12 Jun 2001 14:48:02 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Why two lists instead of HOH?
Message-Id: <3B2671F2.D9E19E6D@home.com>
Sweth Chandramouli wrote:
>
[Debate of sorting hash keys (possibly using a synthetic index)
versus the coordination required in keeping them in an array.]
> I'd love to see other people's solutions to this problem.
Tie::IxHash
-mjc
------------------------------
Date: Tue, 12 Jun 2001 20:49:23 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Why two lists instead of HOH?
Message-Id: <nfvV6.75508$G5.16127895@news1.rdc1.md.home.com>
In article <3B2671F2.D9E19E6D@home.com>,
Michael Carman <mjcarman@home.com> wrote:
>Tie::IxHash
That's not part of the std distro, though, is it? If at
all possible, I'd rather not have to force anyone using this code to
install a new module, as it will probably end up running on multiple
machines.
-- Sweth.
--
Sweth Chandramouli ; <sweth+perl@gwu.edu>
------------------------------
Date: 12 Jun 2001 15:12:02 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Why two lists instead of HOH?
Message-Id: <m3d789lap9.fsf@dhcp9-173.support.tivoli.com>
On Tue, 12 Jun 2001, sweth+perl@gwu.edu wrote:
> . It's a mixed bag, though; every time I want to reorder
> %some_hash, I have to manually renumber all of the sort keys between
> the old and new positions of the moved item. I'm seriously leaning
> towards switching to the hash+array method, plus a validation sub
> that runs after both are defined to make sure that every item in the
> hash has an entry in the array and vice versa.
>
> I'd love to see other people's solutions to this problem.
I haven't used it myself (well, a tiny bit just before posting this),
but I assume that Tie::IxHash is another solution to this problem.
And from what I've seen so far, it seems like a pretty good solution.
It removes the data duplication issue, as well as the reordering
issue.
--
Ren Maddox
ren@tivoli.com
------------------------------
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 1121
***************************************