[19860] in Perl-Users-Digest
Perl-Users Digest, Issue: 2055 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 2 14:05:47 2001
Date: Fri, 2 Nov 2001 11:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004727910-v10-i2055@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 2 Nov 2001 Volume: 10 Number: 2055
Today's topics:
'#!/usr/local/bin/perl -s' problem <sdouglass@_%junk%_.arm.com>
ANNOUNCE: Mac::AppleSingleDouble 1.0 released (Jamie Flournoy)
Re: exclusive bind() on Unix Domain Socket? <lhswartw@ichips.intel.com>
Re: Help modifying a sort routine <tsee@gmx.net>
Re: Help modifying a sort routine <tsee@gmx.net>
Re: Help modifying a sort routine (Tad McClellan)
How to build a timer ... <ochampag@nortelnetworks.com>
Re: How to build a timer ... <bart.lateur@skynet.be>
Re: how to debug perl cgi at homepage nobull@mail.com
Re: How to store a table and retrieve items? (Tad McClellan)
Re: How to store a table and retrieve items? <darkon@one.net>
Re: How to: If (exactstring) then.. [learning Perl] <jurgenex@hotmail.com>
Is it possible to convert a UNIX shell command into PER <Dan.Nguyen@lsil.com>
Re: Is it possible to convert a UNIX shell command into (Rafael Garcia-Suarez)
Re: Is it possible to convert a UNIX shell command into <spinler.patrick@mayo.edu>
Modelling/Designing/Documenting Perl with UML (perl misk)
Re: Need help creating a small flatfile DB program (zaltais)
One liners vs. verbose code <lmoran@wtsg.com>
Re: Perl In Web Pages <jurgenex@hotmail.com>
Re: Perl In Web Pages (Tad McClellan)
Perl on Windows2000 <joe.whalen@broadbeam.com>
Re: Problem adding quotes to a message-id <graham.drabble@lineone.net>
Q: exclusive bind() on Unix Domain Socket? <felix_schattschneider@ccmconsult.de>
Serving HTML images (Maarten)
Re: unzipping a password protected zip file.... help <rereidy@indra.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 02 Nov 2001 16:17:21 +0000
From: scott douglass <sdouglass@_%junk%_.arm.com>
Subject: '#!/usr/local/bin/perl -s' problem
Message-Id: <9ruguh$pir$1@cam-news1.cambridge.arm.com>
I'm having trouble with a script like this (adapted very slightly from the
perlrun man page):
--- foo ---
#!/usr/local/bin/perl -s
if ($xyz) { print "$xyz\n" }
-----------
If I invoke this as
./foo -xyz=abc
it prints
abc
as expected.
But if I invoke this as
/usr/local/bin/perl ./foo -xyz=abc
it prints nothing because the '-s' switch on the '#!' line is being ignored.
I do not expect the '-s' switch on the '#!' line to be ignored. man perlrun
says:
> [...] The #! line is always examined for switches as the line is being parsed. [...]
Indeed, if I add other switches like this:
#!/usr/local/bin/perl -snw
The '-n' and '-w' have the expected effects no matter which of the two ways I
invoke the script.
I've tried this on perl 5.6.1, 5.004_04 and 5.002 on Solaris/SunOS 5.6.
Using perl 5.6.1 (ActiveState build 629) on Win2000 neither invocation obeys the
'-s' switch on the '#!' line. Probably because both invocations are equivalent
to 'perl ./foo -xyz=abc'.
Is this a perl bug or have I missed something? If no one "improves my
understanding" I'll send it to perlbug@perl.com.
Thanks.
------------------------------
Date: 1 Nov 2001 13:28:14 -0800
From: jamie@white-mountain.org (Jamie Flournoy)
Subject: ANNOUNCE: Mac::AppleSingleDouble 1.0 released
Message-Id: <tu5iv44nm1k3c6@corp.supernews.com>
NAME
Mac::AppleSingleDouble - Read Mac files in AppleSingle or
AppleDouble format.
SYNOPSIS
use Mac::AppleSingleDouble;
$foo = new Mac::AppleSingleDouble(shift);
$finder_info = $foo->get_finder_info();
print "The file Type is: $finder_info->{'Type'}\n";
print "The file Creator is: $finder_info->{'Creator'}\n";
print "The Finder label color is: $finder_info->{'LabelColor'}\n";
$foo->close();
REQUIRES
Perl5 (tested with 5.005_03; may work with older versions of
Perl 5), the FileHandle module.
EXPORTS
Nothing.
DESCRIPTION
Mac::AppleSingleDouble is a class which knows how to decode the
AppleSingle and AppleDouble file formats. An instance of
Mac::AppleSingleDouble represents one file on disk.
The structure of Macintosh files is unlike the structure of
files on non-Macintosh operating systems. Most operating systems
represent a file as a filename (with the file type appended as a
suffix), a few attribute bits, and a single chunk of data.
Macintosh files consist of a filename, attribute bits, a four-
character file type code ('TEXT', 'APPL', 'JPEG', 'PDF ', etc.),
a four-character file creator code ('MSWD' for Microsoft Word,
'8BIM' for Photoshop, 'SIT!' for StuffIt, etc.), a chunk of
unstructured data called the "Data Fork", and a chunk of
structured data called the "Resource Fork". In order to store
Macintosh files on other computers, some form of encoding must
be used or the resource and attribute information will be lost
(which is OK in some cases). MacBinary, BinHex, and AppleSingle
all encode the original Mac file in a single chunk of data
suitable for export to other operating systems. AppleDouble
encodes all the Mac-only data in one file, but leaves the chunk
of unstructured data in a separate file all by itself, which
allows non-Mac-aware programs to read the unstructured data with
no decoding step. AppleSingle and AppleDouble were originally
developed for A/UX (an Apple Unix flavor discontinued long ago),
and are used by netatalk (an AppleShare file server for Unix
servers and Mac clients).
If you are working Mac files on a Mac (presumably with MacPerl),
you probably do NOT need this class. If you are working with Mac
files on a non-Mac, the files may be encoded in AppleSingle or
AppleDouble format, and this class can be useful if you need to
get at the Mac file attributes such as the Finder label, the
type and creator codes, or the IsInvisible bit.
See the "AppleSingle/AppleDouble Formats for Foreign Files
Developer's Note" and the book "Inside Macintosh: Finder
Interface" from Apple Computer, Inc for more details on the
formats themselves.
METHODS
Creation
$applefile = new Mac::AppleSingleDouble($filename)
Creates a new Mac::AppleSingleDouble object to represent the
file named in $filename.
Cleanup
$applefile->close()
Closes the underlying AppleSingle or AppleDouble file.
Access
$applefile->get_finder_info()
Returns a hash containing Finder information decoded from
the FInfo and FXInfo data structures.
$applefile->get_entry($id)
Returns the raw binary data of an entry, given its ID. Types
defined by Apple are: 1: Data Fork 2: Resource Fork 3: Real
Name 4: Comment 5: Icon, B&W 6: Icon, Color 8: File Dates
Info 9: Finder Info 10: Macintosh File Info 11: ProDOS File
Info 12: MS-DOS File Info 13: Short Name 14: AFP File Info
15: Directory ID
$applefile->get_file_format()
Returns 'AppleSingle', 'AppleDouble', or 'Plain' based on
the "magic number" found at the beginning of the file.
(0x00051600 is AppleSingle, 0x00051607 is AppleDouble, and
anything else is Plain.)
$applefile->is_applesingle()
Returns 1 if the file format is AppleSingle. See
get_file_format().
$applefile->is_appledouble()
Returns 1 if the file format is AppleDouble. See
get_file_format().
$applefile->get_entry_descriptors()
Returns a hash with entry IDs as keys, and hash references
as values. The references hashes contain three keys:
EntryID, Offset, and Length. Offset is the offset from the
start of the file to the entry data, and Length is the
length of the data, both in bytes. (There are higher-level
methods to access entry data so most users will not need to
call this method.)
$applefile->get_all_entries()
Returns a hash with entry IDs as keys, and raw entry data as
values. All entry IDs found in the file will be returned.
$applefile->dump()
Dump a formatted ASCII representation of the contents of the
AppleSingle or AppleDouble file to STDOUT.
$applefile->dump_header()
Dump the filename and file size and header information to
STDOUT. The header information includes: magic number,
format version number, and all entry descriptors (entry ID,
offset, and length of each).
$applefile->dump_entries()
Print a hex dump of the entry data for all entries in the
file to STDOUT.
$applefile->dump_entry($id)
Print a hex dump of the entry data for the specified id to
STDOUT.
Configuration
$applefile->set_labelnames(%new_labelnames)
Given a hash with keys 0 through 7 and string values, change
the values corresponding to the LabelName key in the hash
returned by get_finder_info(). Note that 0 should always be
'None' since it cannot be changed in the Finder, and the
menu in the Finder lists labels in descending order
(starting with 7 and counting down to 1).
$applefile->set_labelcolors(%new_labelcolors)
Given a hash with keys 0 through 7 and string values, change
the values corresponding to the LabelColors key in the hash
returned by get_finder_info(). Note that 0 should always be
'Black' or 'None' since it cannot be changed in the Finder,
and the menu in the Finder lists labels in descending order
(starting with 7 and counting down to 1).
$applefile->preload_entire_file()
Loads all the entry data from the file into memory and
closes the underlying file.
$applefile->cache_entries()
Causes subsequent entry data accesses to be cached in memory
in the object.
DIAGNOSTICS
The constructor (new) requires a filename as an argument!
(F) The constructor (new Mac::AppleSingleDouble($filename))
was called but the required filename argument was not
defined. The path to the AppleSingle or AppleDouble file to
be examined must be passed to the constructor.
File '/usr/bin/perl' is not in AppleSingle or AppleDouble format!
(F) The file was readable but did not start with the "magic
number" denoting AppleSingle or AppleDouble format.
'..' is not a file!
(F) The filename specified in the constructor does not point
to a file.
BUGS
The AppleSingle and AppleDouble formats come in two versions - 1
and 2. I was unable to find documentation for version 1 -
supposedly there is a manual called "A/UX Toolbox: Macintosh ROM
Interface", but I was unable to find it. However, netatalk uses
version 1. So, this class was coded using the version 2
specification but it was tested on version 1 files written by
netatalk. Entry ID 7 appears in version 1 files but I have no
idea what it means. However, it seems to work...
RESTRICTIONS
This module can read AppleSingle and AppleDouble files, but it
cannot create or modify them. It's not worth my time to change
it so that it can (testing it thoroughly with other programs
which use the files would be very time consuming), so I probably
won't do it. If you want to make that enhancement and send your
changes to me, I would be happy to integrate them into a new
version and to give you credit for your work.
AUTHOR
Jamie Flournoy, jamie@white-mountain.org
-------------------------------------------------------
The uploaded file
Mac-AppleSingleDouble-1.0.tar.gz
has entered CPAN as
file: $CPAN/authors/id/J/JF/JFLOURNOY/Mac-AppleSingleDouble-1.0.tar.gz
size: 16047 bytes
md5: 96343f4314905602f96e379baa25996f
------------------------------
Date: Fri, 2 Nov 2001 09:47:21 -0800
From: "Swanthog" <lhswartw@ichips.intel.com>
Subject: Re: exclusive bind() on Unix Domain Socket?
Message-Id: <9rum7a$ier@news.or.intel.com>
Felix,
The way I got around this problem on windows was by creating a file
semaphore. In this way, the second server won't bind to the port unless the
semaphore is released by the first. The problem with this is that someone
else's server could still bind to the port but that's not likely to happen
in my environment.
E.g. ( in each server's initialization routine),
until( $success)
{
if( sysopen( LOCK_FILE, 'c:/legos/legodbrc.lock', O_CREAT) &&
flock( LOCK_FILE, LOCK_EX | LOCK_NB ))
{
$success = 1;
}
if( time >= $timeout)
{
$messg .= "***> Timeout Occurred! <***\n";
$messg .= "LegoRCs is already running on this machine.\n";
print $messg;
exit;
} else {
sleep $sleep_time;
}
}
Hope this helps,
Larry S.
"Felix Schattschneider" <felix_schattschneider@ccmconsult.de> wrote in
message news:9rujer$voqe0$1@ID-13380.news.dfncis.de...
> Hi,
>
> here's my problem:
> I wrote a small server which listen()s on a Unix Domain Socket
> <snip>
> $server = IO::Socket::UNIX->new( Type => SOCK_STREAM,
> Local => $SOCKNAME,
> Listen => 1);
>
> die "Cannot setup server $!" unless $server;
> </snip>
> but I don't want a second instance of that server being able to bind() to
> that socket $SOCKNAME (which it does at the moment).
> Is there any way to do this?
> I didn't find anything in the IO::Socket manpage and it doesn't make sense
> to flock() the socket (I need my clients to connect to it)
>
> Thanks for any hints
>
> Felix
>
------------------------------
Date: Fri, 2 Nov 2001 18:01:25 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Help modifying a sort routine
Message-Id: <9rujft$acc$02$1@news.t-online.com>
"Steffen Müller" <tsee@gmx.net> schrieb im Newsbeitrag
news:9rudrq$8u1$03$1@news.t-online.com...
| Please note that the latter part (foreach) won't work if the character
| you're sorting by isn't found. The loop will just iterate over the whole
| array. Afterwards, it's in the same order as before. You would need a
better
| routine if you wanted the data to start with the first element
| alphabetically *after* the desired one.
This should work.
#!/bin/perl
use strict;
use warnings;
my @ary = ('ABC', 'aBC', 'Ba', 'cc'..'dd');
@ary = reverse @ary; # To make the sort a little more interesting.
my $sort_by = 'b'; # that's a 'd'. Characters work here, too.
# In order to sort by a number, you need to pass
# its ASCII value.
# always lower case.
my @sorted = sort_link( $sort_by, @ary );
sub sort_link {
my $sort_by = shift;
my @ary = @_;
$sort_by = ord($sort_by) if ( $sort_by !~ /^\d+$/ );
# convert to ASCII value if it's not a number.
@ary = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_,
chr(
(
ord(
substr( lc($_), 0, 1 )
) - $sort_by
) % 256
) .
substr( lc($_), 1 ) ] } @ary;
return @ary;
}
print $_."\n" foreach (@sorted);
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Fri, 2 Nov 2001 18:25:27 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Help modifying a sort routine
Message-Id: <9rukrn$7gr$07$1@news.t-online.com>
"Steffen Müller" <tsee@gmx.net> schrieb im Newsbeitrag
news:9rujft$acc$02$1@news.t-online.com...
| This should work.
It should, but I forgot the explanation.
Reformatted:
@ary = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_,
chr(
(
ord(
substr( lc($_), 0, 1 )
) - $sort_by
) % 256
) .
substr( lc($_), 1 )
] } @ary;
What we do here is, instead of just sorting by the lower case array elements
lc($_), we also substitute the first character. By doing that, we are able
to have the sort routine sort the array and return the elements with
$sort_by as their first character first.
Almost the whole tree of parens is just for the substitution, so again, we
start at the end. Before continuing, you should read about substr() and all
its forms (2/3/4 attributes).
The expression 'substr( lc($_), 1 )' returns all characters of the lower
case version of the array element starting from the second character. (0
would have been the first.) The dot in the previous line is a concatenation
dot - for joining to strings. We join the modified first character and the
lower case rest of the element.
Now to the first character. For that, we jump to the middle of the
expression: to 'substr( lc($_), 0, 1 )'. This grabs 1 char of lc($_)
starting at position 0. ord() then takes its ASCII value and $sort_by (also
an ASCII value) is subtracted. To the outcome, we then apply modulo 256 (256
ASCII chars total) to wrap any negative values (eg $sort_by greater than the
ASCII value of the character). These will then become 256 + [negative
value].
The outcome of the modulo will then be transformed back to an ASCII char.
The char you'
re sorting by will become chr(0), a.s.o. The sort actually sorts on the
ASCII value of the characters, so this will place the elements with
chr($sort_by) as first character in the first elements of the array.
Because we sort on weird-looking data that's meant for computers not humans,
we take the original data from the anonymous arrays within each (outer)
array element using map, but you already know that.
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Fri, 02 Nov 2001 17:38:50 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help modifying a sort routine
Message-Id: <slrn9u5jd1.dfu.tadmc@tadmc26.august.net>
Steffen Müller <tsee@gmx.net> wrote:
>> my ($num) = ($#unsorted+1) / ($#db_cols+1);
> ^ ^ ^ ^ ^ ^
>Parens enforce list context.
^^^^^^^
That is too strong a term. "Parens allow list context" is more accurate.
( and parens do NOT make a list, they are very often needed for
precedence reasons though.
)
For an example of parens that do NOT force a list context, we have
to look no further than the code above, which contains 2 sets
of parens (the 2nd two) that do not effect context :-)
my ($num) = (context()) / 10;
sub context { print wantarray ? 'list' : 'scalar' }
shows that context() was called in a scalar context, whether
wrapped in parens or not.
What determines the context is the _operators_ involved in the
part of the expression being evaluated.
Division gives scalar context to both of its operands (but you
already knew that judging by the code below that I snipped).
>They're not necessary here.
That part is true enough.
>#!/bin/perl
>use strict; # always!!!
>use warnings; # always!!!
Nothing to add here, but it bears repeating so I'll leave it in :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 2 Nov 2001 17:04:53 +0100
From: "Olivier" <ochampag@nortelnetworks.com>
Subject: How to build a timer ...
Message-Id: <9rug95$d8j$1@bcarh8ab.ca.nortel.com>
Hi all,
I need to do a timer in millisecond ... as a function :
Timer(x millisecond, action) will execute the action in x millisecond and
not in second...
What kind of function date/time/ ??? should be good for that ?
Thanks.
Olivier
------------------------------
Date: Fri, 02 Nov 2001 16:30:34 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How to build a timer ...
Message-Id: <2ci5ut08qe8356u0d42loc0rl5a6ld5bgb@4ax.com>
Olivier wrote:
>I need to do a timer in millisecond ... as a function :
>
>Timer(x millisecond, action) will execute the action in x millisecond and
>not in second...
>What kind of function date/time/ ??? should be good for that ?
I'm not exactly sure what you want to do... do ou want to execute this
thing once, or every x seconds? What happens in the meantime?
For a start, look at the module Time::HiRes. It contains a substitute
for the built-in sleep() with finer-than-whole-seconds resolution. Add a
fork() (even on modern Win32 perls) and you've got something that could
just work.
--
Bart.
------------------------------
Date: 02 Nov 2001 17:10:33 +0000
From: nobull@mail.com
Subject: Re: how to debug perl cgi at homepage
Message-Id: <u9vggt5cae.fsf@wcl-l.bham.ac.uk>
"Alex CTK" <tkcheung@vtc.edu.hk> writes:
> I am running a perl script at apache web server. I would like to know how to
> make it run the debug for perl.
The following assumes a Unix-like OS. It also assumes CGI not mod_perl.
First you need a tty with which to interact with the debugging.
Get one by your faviourate method. Xterm, or telnet from a window box or
Make the tty public and then make the job in that window sleep.
tty; chmod a+rw `tty`; sleep 3600
Next edit your .htaccess to contain somthing like:
SetEnvIf Request_URI ^ PERLDB_OPTS=TTY=/dev/pts/3
(Substitue the name of your tty for "/dev/pts/3")
Finally put a -d on the script's shebang line.
If you are doing this sort of thing a lot you probably should look
into writing a Term::Rendezvous implementation to automatically spawn
a window on your console when a background process goes into debug.
Aside: Are there any nice modules to make implementing a
Term::Rendezvous simpler?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 02 Nov 2001 17:38:52 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to store a table and retrieve items?
Message-Id: <slrn9u5jq8.dfu.tadmc@tadmc26.august.net>
Mina Naguib <spam@thecouch.homeip.net> wrote:
><ississauga@hotmail.com> wrote in message news:3be29bfa.3163724@news...
>> How can the table be stored
>What type of data structure is this table stored in ?
I think you have reasked the OP's original question :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 02 Nov 2001 18:43:11 -0000
From: David Wall <darkon@one.net>
Subject: Re: How to store a table and retrieve items?
Message-Id: <Xns914D8B7B2C6A3darkononenet@207.126.101.97>
ississauga@hotmail.com wrote on 02 Nov 2001:
>
> A table has prices for items having width and height,
>
> 3 6 8
> 2 212 229 246
> 6 230 244 274
> 9 241 271 291
>
> So if the item is
> width=5.9
> height=2
> price=229
>
> How can the table be stored and prices found when a width and height
> is given? I was trying this method but there must be a better way.
> If ($width <= 3) && ($height<=2) { $price=212; }
>
> Any solutions??
Here's a fairly simple way to do it by storing the table in a hash. I'm
not sure if it's appropriate for your purposes or not.
use strict;
use warnings;
my $width = 5.9;
my $height = 2;
my %table = ( # height, width
2 => { 3 => 212, 6 => 229, 8 => 246 },
6 => { 3 => 230, 6 => 244, 8 => 274 },
9 => { 3 => 241, 6 => 271, 8 => 291 }
);
# width category
my $w_cat = $width <= 3 ? 3 :
$width <= 6 ? 6 :
$width <= 8 ? 8 :
undef;
# height category
my $h_cat = $height <= 2 ? 2 :
$height <= 6 ? 6 :
$height <= 9 ? 9 :
undef;
my $price = $table{$h_cat}{$w_cat} if $w_cat && $h_cat;
__END__
You could also use an array, which is probably faster in computer terms,
but IMHO if you use something like the above, an array would increase the
risk of programmer error. The reason is that price for height=2 width=3
would be in $table[0][0], which seems pretty non-intuitive to me. YMMV.
The above is also crude because everything is hard-coded. If you add rows
or columns to the table you have to go back and edit the definitions of
$w_cat or $h_cat.
If you use Jeff Zucker's AnyData module then you can expand the table at
will and not have to worry. Well, not much -- you do have to make sure
that each combination of height category and width category is unique. I
also didn't add a test for what happens if you try to retrieve something
like, say, height=20 and width=20.
use strict;
use warnings;
use AnyData;
my $width = 5.9;
my $height = 2;
my $table = adTie( 'ARRAY',
[['hcat','wcat', 'price'],
[ 2, 3, 212],
[ 2, 6, 229],
[ 2, 8, 246],
[ 6, 3, 230],
[ 6, 6, 244],
[ 6, 8, 274],
[ 9, 3, 241],
[ 9, 6, 271],
[ 9, 8, 291]]
);
my $price = $table->{
{wcat => ">= $width", hcat => ">= $height"}
}[0]{'price'};
__END__
There may be a more convenient way to use AnyData to do this; I'm not
fully comfortable with it. Jeff, are you out there?
--
David Wall
darkon@one.net
------------------------------
Date: Fri, 2 Nov 2001 09:11:00 -0800
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How to: If (exactstring) then.. [learning Perl]
Message-Id: <3be2d3a9$1@news.microsoft.com>
"Emping Melindjo" <emelindjo@hotmail.com> wrote in message
news:9rtuqv$1hkk$1@scavenger.euro.net...
> I want to test the exact content of: ($Category{$line})
> if ($Category($line) = "bike" then ...
Couple of issues:
- the brackets are unbalanced
- the keyword to open a new block is "{" instead of "then"
- to access the value of an element in a hash you use curly braces, not
brakets (you got it right in the text and wrong in the code)
- the single "=" is the assignment operator, i.e. your are assigning the
value "bike" to $Category{$line} and then the "if" tests the return value of
the assignment. Not very useful.
Instead you want to use "eq" which compares text.
- a minor issue: You don't need any stringification on the text "bike" (it
doesn't contain any variables or special characters which would need to be
interpreted). You should get into the habit of using single quotes instead
of double quotes for those strings.
if ($Category{$line} eq 'bike') {
jue
------------------------------
Date: Fri, 2 Nov 2001 10:00:55 -0600
From: "Dan Nguyen" <Dan.Nguyen@lsil.com>
Subject: Is it possible to convert a UNIX shell command into PERL?
Message-Id: <9rug2a$e4o$1@news.lsil.com>
I would like to convert one of the two lines below from UNIX shell into perl
but I was not able to do it.
Please HELP HELP HELP!
find . -name "*.h" -follow -print | sed -e 's/^/\"/;s/$/\"/' | xargs
wc -l | sed '$\!d' | nawk '{print $1}'
OR
wc -l "`find \. -name '*.h' -follow -print`" | sed '$\!d' | nawk
'{print $1}'
Thank you so much for all of your help, Dan
------------------------------
Date: 2 Nov 2001 16:17:40 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Is it possible to convert a UNIX shell command into PERL?
Message-Id: <slrn9u5hpr.pmb.rgarciasuarez@rafael.kazibao.net>
Dan Nguyen wrote in comp.lang.perl.misc:
> I would like to convert one of the two lines below from UNIX shell into perl
> but I was not able to do it.
> Please HELP HELP HELP!
>
> find . -name "*.h" -follow -print | sed -e 's/^/\"/;s/$/\"/' | xargs
> wc -l | sed '$\!d' | nawk '{print $1}'
A good start is to look at the File::Find perl module, and at the
find2perl utility, that converts find(1) commands to perl code (that
uses File::Find).
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
But what about a bit of artistic license?
-- Monty Python, The Penultimate Supper
------------------------------
Date: Fri, 02 Nov 2001 12:50:21 -0600
From: Patrick Spinler <spinler.patrick@mayo.edu>
To: Dan Nguyen <Dan.Nguyen@lsil.com>
Subject: Re: Is it possible to convert a UNIX shell command into PERL?
Message-Id: <3BE2EAEC.3018867@mayo.edu>
Dan Nguyen wrote:
>
> I would like to convert one of the two lines below from UNIX shell into perl
> but I was not able to do it.
> Please HELP HELP HELP!
>
> find . -name "*.h" -follow -print | sed -e 's/^/\"/;s/$/\"/' | xargs
> wc -l | sed '$\!d' | nawk '{print $1}'
perl -MFile::Find -e 'File::Find::finddepth (sub {$lines += `wc -l $_`
if ($_ =~ /\.h$/)}, "."); END { print "$lines\n" }'
(forgive the bad wrapping, this was all one line)
I'm not a perl guru so I'm certain someone can improve on this,
especially in the speed of execution.
-- Pat
--
This message does not represent the policies or positions
of the Mayo Foundation or its subsidiaries.
Patrick Spinler email: Spinler.Patrick@Mayo.EDU
Mayo Foundation phone: 507/284-9485
------------------------------
Date: 2 Nov 2001 08:56:29 -0800
From: perlmisk@yahoo.co.uk (perl misk)
Subject: Modelling/Designing/Documenting Perl with UML
Message-Id: <7fe42fcd.0111020856.67ba07fe@posting.google.com>
I am interested in using UML to model my Perl applications and
modules.
To learn UML I am using Select with my first diagram being a Class
Diagram.
What is the best choice to model parts of my Perl? I think I should
use the following, but would like to take the chance to check with
someone that knows :)
Perl Modules: packages
Subs: class
Perl Executable: packages
I'm not looking for a huge amount of detail whilst I am learning UML
(and Perl) but would rather get it right first time.
The biggest proble with above is I have organised my application to
follow the standard *NIX filesyste convention, ~/bin, ~/etc, ~/log,
blah... so I am uncertain as to which UML component to model a
directory - or is that not the right way to think about UML? My
primary use of it is realisticly speaking for documentation and both
functional and technical specifications as opposed to using its power
as a design modelling tool until I am more familiar with it.
Are there any working exampls of UML and Perl?
btw, is either Select of Visio streets ahead of the other as I have
access to both but I have almost randomly picked Select?
Regards
Andrew
------------------------------
Date: 2 Nov 2001 10:18:05 -0800
From: zaltais@oceanfree.net (zaltais)
Subject: Re: Need help creating a small flatfile DB program
Message-Id: <919d9cd5.0111021018.31f9efcc@posting.google.com>
I'm only new to perl myself, so someone will probably give you a much
better way of doing this, but the easiest way I think you could do
this is use javascript for the time script - get the javascript timer
to start when you hit start and write the time to your start-time text
box, when you hit stop, write the time now to your stop-time text box.
When you are opening your file first you want to open it to read,
write, and append mode using
open (FILEHANDLE, "+>>filename");
and this; I think, should work...
(haven't tested it though)
Cheers,
Zaltais
"Robert Valcourt" <rvalcourt@telus.net> wrote in message news:<RJuE7.11572$i4.1113559@news0.telusplanet.net>...
> Hey everyone,
>
> I am very new to Perl. My boss has given me the task of creating a small
> "time tracking" program using perl on the web out of a CGI-BIN. What I need
> it a perl created page that has two text fields, a start and stop button, a
> description field, and a submit button. Here is what it would do.
>
> When I am given a job, this program would be used to track my labour hours.
> I would go to this page and hit start. When my job is finished I would press
> stop. The start and stop time would be shown in the two text fields. EG :
>
> In the first text field : 08:00
> In the second text field : 08:30 ( times just used as an example )
>
> This of course would mean I hit the start button at 8AM and hit the stop
> button at 8:30AM. The page would also have a "work description" textarea box
> where I could describe the job performed. Once this info has been filled
> out, I would hit submit and the data would be sent to a flatfile text based
> database. I would like the flatfile database to hold multiple jobs. A
> theoretical "week old" database would look like this:
>
> 08:00 - 08:30 - November 1 - Fixed broken link
> 09:22 - 09:58 - November 2 - Fixed broken link
> 08:05 - 10:47 - November 3 - Fixed broken link
> 04:00 - 05:33 - November 4 - Fixed broken link
>
> This of course means that each time I use the time tracker, and submit the
> info, the info is compiled in the database instead of overwriting old data.
> Now I am familiar enough with Perl to be able to open and save data to
> files. I am not, however, able to compile data without overwriting the old
> data. I am also not able to create the timer code.
>
> Can someone(s) please help me with this? some code examples or direction
> would be most appreciated! And I would return the favour anytime!
>
> TIA to all!
>
> Rob
------------------------------
Date: Fri, 02 Nov 2001 13:26:51 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: One liners vs. verbose code
Message-Id: <50p5utkpm6h2drvnau4o2q5s6s6pbqg7pl@4ax.com>
--I realize perlgolf is for fun but I have been wondering lately if
there is any reason to code in a golf-esque manner.
--Would it make programs/scripts run faster or would it just make the
next Sys Admin's job harder?
--(This all started when my boss put one of my scripts on a projector
and said to a group (essentially) "I don't want you all coding like
this. It's too clear." (I comment, a lot... but I write scripts and
then don't go back to them for months...OK I'm not all that bright,
there I said it)) (:
--
TMTOWTDI: My way tends to be wrong...
lmoran@wtsg.com
------------------------------
Date: Fri, 2 Nov 2001 09:26:12 -0800
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl In Web Pages
Message-Id: <3be2d734$1@news.microsoft.com>
"Brendan" <brendandonhue@aol.com> wrote in message
news:86a94b1e.0111020642.2f3814ad@posting.google.com...
> Whenever I run a PERL script, it executes in a DOS windows. Is there a
> way to have it execute through a browser window so that it can be part
> of my web site?
Actually, it's more the other way round.
You always run Perl script from a DOS window (speaking Windows talk here).
It is just a convenience that the OS starts a new DOS Window for you
automatically if you are not using one already.
Note: ActiveState Perl includes an additional executable wperl.exe which
will not open a DOS window, quite useful for e.g. demons and services.
"to have it execute through a browser window": Well, no, not really.
Browsers display HTML files, they have nothing to do with the execution of
programs as such (there are exceptions, but I think you were not asking
about ActiveX, OCX, or client side scripting).
I'm guessing you want to run the script on a web server and have the
generated HTML output being displayed on a client browser? In that case you
should read up on CGI which is quite off-topic in this NG.
jue
------------------------------
Date: Fri, 02 Nov 2001 17:38:51 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl In Web Pages
Message-Id: <slrn9u5jmr.dfu.tadmc@tadmc26.august.net>
Mina Naguib <spam@thecouch.homeip.net> wrote:
>
>"Brendan" <brendandonhue@aol.com> wrote in message
>news:86a94b1e.0111020642.2f3814ad@posting.google.com...
>> Whenever I run a PERL script, it executes in a DOS windows. Is there a
>> way to have it execute through a browser window so that it can be part
>> of my web site?
You will need to install a http server if you want to play with
CGI programs locally. There are free ones available.
>That would make it a CGI.
No, that would make it a CGI program.
The Common Gateway Interface has already been made some time ago.
>Look into your browser's configuration files to see how you can get it to
>execute CGIs for you, and read about CGIs.
^^^^^^^^^^^^^^
Perhaps you should do a bit of that too, as browsers do NOT
"execute CGIs for you".
In a CGI environment, the browser's role is nothing more than
an input/output device for a CGI program that runs on a *server*.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 2 Nov 2001 12:49:40 -0500
From: "Joseph J. Whalen" <joe.whalen@broadbeam.com>
Subject: Perl on Windows2000
Message-Id: <r1BE7.10825$ym4.472552@iad-read.news.verio.net>
I am interested in running Perl on Windows 2000 in order to support perl CGI
scripts through IIS. I have a copy of ActivePerl installed on the system.
In all of the FAQ's that I've seen, it is recommended to also use
cgi2shell.exe. I can not seem to find this utility anywhere for download.
My questions:
1. Is there someplace this can be downloaded from? If so, where.
2. Are there any other utilities I can use to replace the functionality
cgi2shell provides?
3. Is there another way to get perl CGI's working under IIS other than the
path that I've taken.
If anyone has any helpful information please feel free to email me. Thank
you for any assistance you can provide.
------------------------------
Date: 2 Nov 2001 18:40:36 GMT
From: Graham Drabble <graham.drabble@lineone.net>
Subject: Re: Problem adding quotes to a message-id
Message-Id: <Xns914DBB5A0769Cgrahamdrabblelineone@ID-77355.user.dfncis.de>
tadmc@augustmail.com (Tad McClellan) wrote in
news:slrn9u44hi.b1s.tadmc@tadmc26.august.net:
> Graham Drabble <graham.drabble@lineone.net> wrote:
>>tadmc@augustmail.com (Tad McClellan) wrote in
>>news:slrn9u3qj5.aog.tadmc@tadmc26.august.net:
>>
>>> use warnings;
>>> use strict;
>>
>>Adding thse did not help. I know I probably ought to declare
>>variables bet I'm lazy.
> ^^^^^^^^
>
> No you're not. Lazy programmers want all the help they can get.
>
> Hard working programmers would rather spend minutes/hours/days
> debugging something themselves instead of having a machine
> find the problem in milliseconds.
As you've probably guessed by now I'm very new to perl so I'm happy to
take advice. I can certainly see why you'd want them in a more complex
script and now I've read the manual on them properly they are being
used.
> I'm just some guy on Usenet, so feel free to ignore me,
You are clearly a better programmer than me therefore I'm grateful for
all the help your prepared to give me.
>>> Did you know that you can use sane slashes in your paths?
>>>
>>> open(MSGIDFILE, 'C:/usenet/msg-id.log') || die ...
>>
>>Why would I want to?
>
>
> Because one of these days you will have part of the path
> in a variable and you will need double quotes, and your
> code's readability will suffer.
OK, I hadn't thought of that. You make another good point.
>>There is next to no chance of me ever running it on a Unix
>>machine.
>
>
> I did not say anything about portability, so I don't know
> what your point is with that part.
>
I thought, but could be wrong, that forward slashes were the only way
in Unix so guessed that that was the problem.
> My fee is that you enable warnings and strictures on all
> of your Perl programs :-)
>
Happily. Thanks for the advice. The questions were only me trying to
understand what was happening better not any criticism of what was
said.
--
Graham Drabble
If you're interested in what goes on in other groups or want to find
an interesting group to read then check news.groups.reviews for what
others have to say or contribute a review for others to read.
------------------------------
Date: Fri, 02 Nov 2001 17:50:50 +0100
From: Felix Schattschneider <felix_schattschneider@ccmconsult.de>
Subject: Q: exclusive bind() on Unix Domain Socket?
Message-Id: <9rujer$voqe0$1@ID-13380.news.dfncis.de>
Hi,
here's my problem:
I wrote a small server which listen()s on a Unix Domain Socket
<snip>
$server = IO::Socket::UNIX->new( Type => SOCK_STREAM,
Local => $SOCKNAME,
Listen => 1);
die "Cannot setup server $!" unless $server;
</snip>
but I don't want a second instance of that server being able to bind() to
that socket $SOCKNAME (which it does at the moment).
Is there any way to do this?
I didn't find anything in the IO::Socket manpage and it doesn't make sense
to flock() the socket (I need my clients to connect to it)
Thanks for any hints
Felix
------------------------------
Date: Fri, 02 Nov 2001 17:44:17 GMT
From: lithotroph@hotmail.com (Maarten)
Subject: Serving HTML images
Message-Id: <914DBE08A12547@24.132.65.7>
Using perl I'm not sure whether this is the right group to ask, but
anyway: does anybody know how to get a browser to not load a image
from the cache but from the server instead while using the html IMG
tag?
Simply setting the last-update header doesn't seem to suffice,
because the browser doesn't seems look at the header if an obsolete
(dynamically served) image of the same name can be found in the
cache.
Thanks
------------------------------
Date: Fri, 02 Nov 2001 10:27:55 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: unzipping a password protected zip file.... help
Message-Id: <3BE2D79B.B947CC7F@indra.com>
Chris Los wrote:
>
> I need to write a script that will unzip a password protected zip
> file.... is there a way to do this in perl???
> Do i need a special module??
>
> TIA
Archive::Zip
--
Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.
------------------------------
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 2055
***************************************