[23032] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5252 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 21 18:06:02 2003

Date: Mon, 21 Jul 2003 15:05:09 -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           Mon, 21 Jul 2003     Volume: 10 Number: 5252

Today's topics:
        Anyone using Perl to develop and deploy MS Windows apps (=?ISO-8859-1?Q?Stefan_Fischerl=E4nder?=)
    Re: Anyone using Perl to develop and deploy MS Windows  <leadbed@hotmail.com>
        DBI reading from csv ? rls@one.net
    Re: DBI reading from csv ? <emschwar@pobox.com>
    Re: DBI reading from csv ? <mothra@nowhereatall.com>
    Re: File::Find is slower than using recursion!? <dwilga-MUNGE@mtholyoke.edu>
    Re: how to convert all invalid UTF-8 sequences to numer (Shambo)
        localize values of an object's hash key <Joly.Patrick@ic.gc.ca>
        New to cig question <his_ron@yahoo.com>
    Re: New to cig question <emschwar@pobox.com>
    Re: New to cig question <his_ron@yahoo.com>
    Re: New to cig question <trammell+usenet@hypersloth.invalid>
        One Off Script (JP Ogden)
        Perl Script to Read Exchange OWA info <masq57@netscape.net>
        perlcc makes it big <butt-fuzz@ass.wipe.com>
    Re: perlcc makes it big (Randal L. Schwartz)
    Re: perlcc makes it big <bobx@linuxmail.org>
        Please critique my 2nd Perl program (generates an aucti <spamblock@junkmail.com>
    Re: push -- weird problem <usenet@dwall.fastmail.fm>
    Re: push -- weird problem <butt-fuzz@ass.wipe.com>
    Re: retrieve wishlist from Amazon <Patrick_member@newsguy.com>
    Re: See y'all in Paris?  YAPC::Europe::2003 <usenet@expires082003.tinita.de>
    Re: Variable reference (Tad McClellan)
    Re: Variable reference <shawn@magma.ca>
    Re: Variable reference <tassilo.parseval@rwth-aachen.de>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 21 Jul 2003 14:24:55 -0700
From: fischerlaender@gmx.de (=?ISO-8859-1?Q?Stefan_Fischerl=E4nder?=)
Subject: Anyone using Perl to develop and deploy MS Windows apps?
Message-Id: <ff9bee6c.0307211324.1a7e5437@posting.google.com>

I'm looking for some experiences or even some guidance ...

There are some freeware tools I provide on my homepage, which are
written in Visual Basic. For a couple of reasons I want to get rid of
VB and want to switch to another language.

Because I'm rather experienced with Perl, this would be an obvious
choice. But there is one problem: the deployment of my Perl apps. My
users are no tech gurus, just average computer users. This means the
programs have to be deployed as self-installing single .exe files. (To
tell them to install ActiveState Perl for Windows distribution is no
option!)

After some googling, I found several tools which together seem to form
a complete development environment to build (simple) Windows
applications:

Perl "Compilers":
http://tinyperl.sourceforge.net/
http://search.cpan.org/author/AUTRIJUS/PAR-0.69/
http://www.indigostar.com/perl2exe.htm

"GUI Builder" for Win32::GUI:
http://www.bahnhof.se/~johanl/perl/Loft/

Installation Program:
http://www.nullsoft.com/free/nsis/


Does anyone here has any experiences with what I intend to do?
Is Perl with any of the perl-to-exe "compilers" a reasonable solution
to create and deploy Windows applications?

Stefan


------------------------------

Date: Mon, 21 Jul 2003 23:53:37 +0200
From: "Richard Bennett" <leadbed@hotmail.com>
Subject: Re: Anyone using Perl to develop and deploy MS Windows apps?
Message-Id: <3f1c6124$0$268$ba620e4c@reader0.news.skynet.be>

Hi,
"Stefan Fischerländer" <fischerlaender@gmx.de>
> Because I'm rather experienced with Perl, this would be an obvious
> choice. But there is one problem: the deployment of my Perl apps. My
> users are no tech gurus, just average computer users. This means the
> programs have to be deployed as self-installing single .exe files. (To
> tell them to install ActiveState Perl for Windows distribution is no
> option!)

I did exactly the same, I also wanted to translate a few VB apps.

What I can highly recommend is Activestate's Perl Dev Kit 5.
It's not free, but there's an eval version. (don't distribute anything built
with it though, as they will also expire)
From the readme: 'you can create standalone ActiveX components, Windows
services, self-contained Windows applications, and .NET compliant objects
and applications'.

You build your app in perl, using win32::gui if you need a gui (or TK), and
then use the dev-kit to compile it into an exe.
It includes all modules and 'require' files within the exe, as well as the
perl interpreter. The end-user just needs to click on your exe to run the
program, no installing or dependancies.
If you want you can also make system-tray programs the same way (with or
without GUI).
In all cases the shell window can be completely hidden.
There's also a visual debugger included.
I found most programs end up around 6 to 700k, which is reasonable, given
that everything that's needed is in there.

I can mail you a program offlist if you'd like to test the look & feel.

Richard.




------------------------------

Date: Mon, 21 Jul 2003 14:29:30 -0400
From: rls@one.net
Subject: DBI reading from csv ?
Message-Id: <dvaohv8shm576bt2evpdhge4t9fhj8tjga@4ax.com>

I am new to PERL, so this question may be trivial to this group.

I have a csv file that I read in a line at a time as a text file then
split on the commas.  I then turn around and write to SQL server using
WIN32 odbc.

This worked fine for about 5000 records.  I fould that there were
about 800 that did not work. When the data is looked at like a CSV
file, such as in Excel, it loads the data in the right fields and even
converts the date fields correctly (something i was getting around by
splittin/joining the data field)  The problem is that one field
contains commas in the data. So reading the data like text the split
function  created to many fields.  I assume CSV reads it correctly
because the offending  field has ,"{ and ]" as field indicators?

So can I use DBI odbc excel to read the CSV correctly and then I can
insert that data into SQL server?  Will it read the fields like I
would see the fields in Excel?   

Any help would be appreciated.

Thanks,

Rob


------------------------------

Date: Mon, 21 Jul 2003 12:45:34 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: DBI reading from csv ?
Message-Id: <eto7k6b67n5.fsf@wormtongue.emschwar>

rls@one.net writes:
> So can I use DBI odbc excel to read the CSV correctly and then I can
> insert that data into SQL server?  Will it read the fields like I
> would see the fields in Excel?   

You can, but that's way overkill.  Why not just use DBD::CSV instead?

perldoc -q 'How can I split' has several other handy answers.

BTW, when searching for this, I was looking for the FAQ on CSV files,
and 'perldoc -q comma' didn't find it, even though the phrase
'Comma-separated files' appears in the topic.  I admit to being
surprised.  How are they indexed?

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


------------------------------

Date: Mon, 21 Jul 2003 11:46:12 -0700
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: DBI reading from csv ?
Message-Id: <3f1ae632$1@usenet.ugs.com>


<rls@one.net> wrote in message
news:dvaohv8shm576bt2evpdhge4t9fhj8tjga@4ax.com...
>
> So can I use DBI odbc excel to read the CSV correctly and then I can
> insert that data into SQL server?  Will it read the fields like I
> would see the fields in Excel?
>
Try DBD::AnyData;


Mothra




------------------------------

Date: Mon, 21 Jul 2003 19:24:28 GMT
From: Dan Wilga <dwilga-MUNGE@mtholyoke.edu>
Subject: Re: File::Find is slower than using recursion!?
Message-Id: <dwilga-MUNGE-277655.15242421072003@nap.mtholyoke.edu>

In article <u3cgz22g9.fsf@wrq.com>, Steve Allan <stevea@wrq.com> wrote:

>    if ( not -l $fileToCheck and -d $fileToCheck ) {
>       chdir $fileToCheck or die "Can't cd to $fileToCheck: $! ";
>       ...
> 
> and with that one change, the recursive version is the slowest.

Try it as:

  if ( not -l $fileToCheck and -d _ ) {

Using a single _ is shorthand for "reuse the stat data from the last 
stat or -X operation." You may be able to use this to speed things up in 
other places, as well.

-- 
Dan Wilga          dwilga-MUNGE@mtholyoke.edu
** Remove the -MUNGE in my address to reply **


------------------------------

Date: 21 Jul 2003 11:50:05 -0700
From: shambo_p@yahoo.com (Shambo)
Subject: Re: how to convert all invalid UTF-8 sequences to numeric equivalent?
Message-Id: <72190192.0307211050.8441493@posting.google.com>

> You haven't addressed the question, though.  Here you're showing what
> you reckon to be part of a solution, but you still haven't shown us
> what your input data is like.
> 
> Is it encoded in utf-8 ?  iso-8859-1 ? (Windows-1252> shudder),
> utf-16LE or what??  If you won't show us, and you're not sure
> yourself, it's hard to advise.

When reading the file into a Perl script, I am letting Perl decide
what the encoding is. Trial and error with specifying an input
encoding showed there was no harm in letting Perl decide. The only
reason I have any doubt about the input encoding being UTF-8 is that
the original file displays a Euro currency symbol properly (in
UltraEdit 32). I was under the impression the Euro symbol is beyond
the UTF-8 range, so I tried opening the source file in XMLSpy (v4).
That program indicated the encoding was UTF-8, and would not display
the Euro symbol properly.

> As the article says: both XML and Perl are quite happy to work
> with unicode characters.  The possible motivation for resorting to
> &-notations would be when you have to tangle with non-XML applications
> which might not be unicode-capable.  If you have such a constraint, I
> must admit I don't recall you saying so.  And XML-based tools can map
> between unicode characters and &-notation for you without fuss, if the
> need arises.

Yes, this is exactly the case. When reading the converted XML files
into Netscape 7 (WinNT), characters such as the Euro will not display
if left in their raw form. That's what led me down the "numeric
equivalent" path.

From one of yesterday's postings, titled "XML attributes and values",
I found a reference to http://perl-xml.sourceforge.net/. In the FAQ on
this site, I was able to find a good deal of information about
encodings, and, finally, the line of Perl code I was looking for all
along:

$line =~ s/([^\x20-\x7F])/'&#' . ord($1) . ';'/gse;

Finally understanding how to represent characters within Perl using
the \x00 notation was a huge leap, as was understanding the ord()
function. You had hinted towards these items ealrier, Alan, I just
didn't make the connection between the two until now.

I have made a few additions to the above line, such as allowing for
tabs and carriage returns to not have to be converted to their numeric
equivalent and removing all other control characters.

$line =~ s/([^\x01-\x7F])/'&#' . ord($1) . ';'/gse; #change all
non-US-ASCII characters to numeric equivalent
$line =~ s/[\x01-\x08]//gs; #removes first group of control characters
$line =~ s/\x0B//gs; #remove this control character
$line =~ s/[\x0E-\x1F]//gs; #removes all other control characters

Then specifying UTF-8 as the output encoding from Perl, although may
be overkill, allows the file to parse against the Xerces parser, and
display properly in Netscape 7. I'm leaving the output encoding in,
although I suspect it's not necessary after the above conversion.

One caveat, the above method converts the Euro symbol to &#128;. This
displays as a question mark in Netscape 7, so I've included the
following line to make it display preoperly:

$line =~ s/\&#128\;/\&#8364\;/gs;

Gonna find out why that is. Makes me wonder if I'll see other
unexpected results from the first conversion line.

Again, thanks for the continued input.

cheers,
S


------------------------------

Date: Mon, 21 Jul 2003 17:16:32 -0400
From: "Joly, Patrick: IAC" <Joly.Patrick@ic.gc.ca>
Subject: localize values of an object's hash key
Message-Id: <3E3612E8D41DD3118DCC0600000000000AEA96CB@pubgate-01.ic.gc.ca>

I need to localise (dynamically scope) the value of a hash key in an
object but I am facing a hurdle.  I have been stuck on this problem for
5 days so any help would be greatly appreciated.

First, some background:  my module is a parser to read binary files from
a database/statistics software.  (See below for what a typical object
looks like.)  The source data contains mnemonics for each variable in a
database and my methods allow one to perform operations by invoking just
those mnemonic names, e.g.

   $oo->read('c:\auto2.dta');           # see below for example of data
   $oo->generate('newvar', 'mpg + 2')
   $oo->replace('mpg', 'mpg/100')

I wrote a method to return a mnemonic name guaranteed to be unique and
want to subsquently use this name in any method to perform operations on
this temporary hash key.  That is, 

   $tempname = $oo->tempvar()  # generate mnemonic guaranteed to be
                   # unique, i.e. generally returns that
                   # look like '__000001'

followed by,

   local $oo->{DATA}{"$tempname"};
   $oo->any_method( ... );

would allows the user to have access to dynamically scoped values for
the temporary hash key (all methods called within that scope have access
to it) but where it would vanish once its localized values go out of
scope (since it wasn't defined in the first place);  Obviously, I don't
want users to access by refering to the key explicitely.  I initially
thought I could modify tempvar() to return the literal string
'$oo->{DATA}{__000001}' rather than simply '__000001' but local() won't
accept any subsequent

   local $tempname;
or
   local (eval $tempname);

Thus I am looking for other solutions and am wondering:

1) is there any way in Perl I can declare variables (or hash keys in
this instance) in the scope of the *calling* program rather than in the
current scope.  That way, I could ask tempvar() to localize the hash key
entry for '__000001'; or,

2) any other ideas?


Thanks, I am really desperate.  Everything was going great so far, until
I got stumped by this.


Patrick Joly, Economist
Industry Canada


A typical object for my module (Stata::Data)
--------------------------------------------
Once dumped using Data::Dumper, it looks like,


$VAR1 = bless( {
         'LABEL' => 'Automobile Data',
         'SORTEDBY' => [
                 'mpg',
                 'turn'
                   ],
<snip>
         'TIMESTAMP' => ' 2 Jul 2003 11:45',
         'FNAME' => 'c:\\auto2.dta',
         'DATA' => {
                 'mpg' => {
                        'FORMAT' => '%8.0g',
                        'CELLS' => [
                             14,
                             14,
                             15,
                             16,
                              ],
                        'LABEL' => 'Mileage (mpg)',
                        'TYPE' => 'int'
                     }
                 'make' => {
                     'FORMAT' => '%-18s',
                     'CELLS' => [
                              'Toyota Echo',
                              'Nissan Sentra',
                              'Ford Focus',
                              'Honda Civic',
                              ],
                       'LABEL' => 'Make and Model',
                       'TYPE' => 'str13'
                     }
<snip>
               }
           }, 'Stata::Data' );




------------------------------

Date: Mon, 21 Jul 2003 18:36:38 GMT
From: "Ron" <his_ron@yahoo.com>
Subject: New to cig question
Message-Id: <WoWSa.93548$hV.6675540@twister.austin.rr.com>

Having problem with this code.
First line works
3rd line works
2nd line I never get a greater than answer even when it's true.

my $size_file = (-s $FILE1)/1024;
if (($size_file > 0)) {
my $YourFiles1 = 'File1: ' . $filename1 . ' ' . $size_file . ' KB';
}

Could anyone let me know what I am doing wrong?

Thanks,
Ron




------------------------------

Date: Mon, 21 Jul 2003 12:40:29 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: New to cig question
Message-Id: <etobrvn67vm.fsf@wormtongue.emschwar>

"Ron" <his_ron@yahoo.com> writes:
> Having problem with this code.
> First line works
> 3rd line works
> 2nd line I never get a greater than answer even when it's true.
>
> my $size_file = (-s $FILE1)/1024;

What is the contents of $FILE1 here?  What is the value of $size_file
here?

> if (($size_file > 0)) {

Ditch the extra set of parentheses.  And when you say the contents of
this if block don't execute even when it's true, how do you know it's
true?  Because you've printed out $size_file, or because you know the
size of the file you think you're looking at?

> my $YourFiles1 = 'File1: ' . $filename1 . ' ' . $size_file . ' KB';

Hrm... above you use $FILE1; here you use $filename1.  Which one
actually contains the name of the file you're looking at?  I'd bet one
or possible both of these is wrong.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


------------------------------

Date: Mon, 21 Jul 2003 19:17:07 GMT
From: "Ron" <his_ron@yahoo.com>
Subject: Re: New to cig question
Message-Id: <T_WSa.87151$XV.5485096@twister.austin.rr.com>

Hi Eric,

I have printed out both
my $size_file = (-s $FILE1)/1024;
is value is 43

I have printed out
my $YourFiles1 = 'File1: ' . $filename1 . ' ' . $size_file . ' KB';
'File1' is just a label
$filename1 is a file name&extension

Thanks,
Ron



"Eric Schwartz" <emschwar@pobox.com> wrote in message
news:etobrvn67vm.fsf@wormtongue.emschwar...
> "Ron" <his_ron@yahoo.com> writes:
> > Having problem with this code.
> > First line works
> > 3rd line works
> > 2nd line I never get a greater than answer even when it's true.
> >
> > my $size_file = (-s $FILE1)/1024;
>
> What is the contents of $FILE1 here?  What is the value of $size_file
> here?
>
> > if (($size_file > 0)) {
>
> Ditch the extra set of parentheses.  And when you say the contents of
> this if block don't execute even when it's true, how do you know it's
> true?  Because you've printed out $size_file, or because you know the
> size of the file you think you're looking at?
>
> > my $YourFiles1 = 'File1: ' . $filename1 . ' ' . $size_file . ' KB';
>
> Hrm... above you use $FILE1; here you use $filename1.  Which one
> actually contains the name of the file you're looking at?  I'd bet one
> or possible both of these is wrong.
>
> -=Eric
> --
> Come to think of it, there are already a million monkeys on a million
> typewriters, and Usenet is NOTHING like Shakespeare.
> -- Blair Houghton.




------------------------------

Date: Mon, 21 Jul 2003 19:34:57 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: New to cig question
Message-Id: <slrnbhog31.pgo.trammell+usenet@hypersloth.el-swifto.com.invalid>

On Mon, 21 Jul 2003 18:36:38 GMT, Ron <his_ron@yahoo.com> wrote:
> my $size_file = (-s $FILE1)/1024;
> if (($size_file > 0)) {
> my $YourFiles1 = 'File1: ' . $filename1 . ' ' . $size_file . ' KB';
> }
>  
> Could anyone let me know what I am doing wrong?
>  

One problem with this code is that you're scoping
$YourFiles1 to the if-block.

How about this as alternative code:

my $YourFiles1 = ($size_file > 0) ?
	"File1: $filename1 $size_file KB" :
	"ack!";

As it stands, I'm not sure how you would ever *tell*
that your code had found a size > 0.



------------------------------

Date: 21 Jul 2003 15:00:52 -0700
From: jp@in3corp.com (JP Ogden)
Subject: One Off Script
Message-Id: <4340eaf1.0307211400.1f121068@posting.google.com>

Fair enough.  I will explain further.  The data is in an Access
Database and contains 5 fields.  I plan to run the PERL script using
ODBC to access the data in the database.  For the sake of this
exercise I will define the fields as follows:
Field 1 - Text
Field 2 - Number (Double)
Field 3 - Date
Field 4 - Text
Field 5 - Text

Here is a sample of my data:
Field 1            Field 2        Field 3      Field 4     Field 5
123                5675.68        5/24/03      Misc        Misc2
E4678              345.76         6/23/02      Test        Test2
123A               8756.67        7/3/03       Code        Code2
0234               10456.45       6/4/02       Man         Man2
234                456.34         10/5/02      Talk        Talk2
675-02             1045.45        3/5/03       Level       Level1
etc...

I would like to isolate only the records where the records in "Field
1" are "one-off."  The results from the above sample would look like
this:
Field 1            Field 2        Field 3      Field 4     Field 5
123                5675.68        5/24/03      Misc        Misc2
123A               8756.67        7/3/03       Code        Code2

and

0234               10456.45       6/4/02       Man         Man2
234                456.34         10/5/02      Talk        Talk2

because the records in "Field 1" are what I am calling "one-off."

The characters in "Field 1" can be anything.  I have attempted to
write the script in VB (I can post if you would like) but I find it
slow and ineffective.  A friend suggested I write it in PERL so here I
am (with limited PERL experience).  Hopefully, this is enough
information.

Any help would be greatly appreciated.  

JP Ogden

Eric Schwartz <emschwar@pobox.com> wrote in message news:<etosmoz6aho.fsf@wormtongue.emschwar>...
> jp@in3corp.com (JP Ogden) writes:
> > I am currently working on a PERL script that will allow me to mine
> > records out of a very large data set (1 million+ records) that have a
> > specific field that is one off (possibly two off).  In other words I
> > would like for my script to find records where "Field A" is 123 and
> > 123B.  Not sure where to start and how to get this done?  Any thoughts
> > would be appreciated.
> 
> As a short aside, consider that when you looked for an answer on
> Google Groups, or whatever your favourite USENET search engine is (you
> *did* look, didn't you?), if you had seen a topic called "One Off
> Script", you probably wouldn't have thought it relevant, right?  If
> you pick Subject: lines that have to do with what you're asking about,
> it helps others find the answers later on, as well.
> 
> Anyway, as per your actual question: until you show us some actual
> data (and preferably, any code you've tried writing already), we can't
> be of much help.  Just to pick one aspect out of the air, we don't
> know if your data is in a flat file, or a database, or available from
> an HTTP server somehow.  We don't know what format it's in.  We don't
> know what "one off" means in this context-- is it the same value as in
> another row, only with one more character appended?  Does the appended
> character have to be a 'B', or just alphabetical, or could it be
> anything?  For that matter, do you want a list of all rows that have
> another row where "Field A" is one off (whatever that means), or do
> you have a 'key row' which denotes the value for rows to be one off
> from?
> 
> I'm not trying to put you or your question down; I just want to point
> out that from all that you've given us so far, the answer could be
> anything from 5 to 50 lines of code (or more).  We simply don't know
> enough to help.
> 
> -=Eric


------------------------------

Date: Mon, 21 Jul 2003 19:57:24 GMT
From: masq57 <masq57@netscape.net>
Subject: Perl Script to Read Exchange OWA info
Message-Id: <3F1C48B9.9000107@netscape.net>


I have been accessing Exchange OWA from my Linux/Mozilla system and 
would like to build a perl script to automatically extract scheduling 
info from the Calendar for use elsewhere.

Just wondering if someone had managed to do that, or could suggest some 
quick starting points to pursue.

Thanks



------------------------------

Date: Mon, 21 Jul 2003 14:05:11 -0400
From: butt-fuzz <butt-fuzz@ass.wipe.com>
Subject: perlcc makes it big
Message-Id: <3F1C2B57.44D98CA9@ass.wipe.com>

I'm running perl 5.8.0 on linux.

I wrote a very simple program:
#!/usr/bin/perl
print "test";

that's it!
and ran perlcc.
it gave me an a.out 1MB in size!
yikes!


------------------------------

Date: Mon, 21 Jul 2003 18:54:11 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: perlcc makes it big
Message-Id: <1651df374de446c67b3b9ff84ac3d9d3@free.teranews.com>

>>>>> "butt-fuzz" == butt-fuzz  <butt-fuzz@ass.wipe.com> writes:

butt-fuzz> I'm running perl 5.8.0 on linux.
butt-fuzz> I wrote a very simple program:
butt-fuzz> #!/usr/bin/perl
butt-fuzz> print "test";

butt-fuzz> that's it!
butt-fuzz> and ran perlcc.
butt-fuzz> it gave me an a.out 1MB in size!

That seems about right.  You have to include all of the Perl engine
to make it work.

What were you actually trying to do?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: Mon, 21 Jul 2003 21:22:45 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: perlcc makes it big
Message-Id: <FQYSa.870$gi.1204077@news2.news.adelphia.net>

"Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message
news:1651df374de446c67b3b9ff84ac3d9d3@free.teranews.com...
> >>>>> "butt-fuzz" == butt-fuzz  <butt-fuzz@ass.wipe.com> writes:
>
> butt-fuzz> I'm running perl 5.8.0 on linux.
> butt-fuzz> I wrote a very simple program:
> butt-fuzz> #!/usr/bin/perl
> butt-fuzz> print "test";
>
> butt-fuzz> that's it!
> butt-fuzz> and ran perlcc.
> butt-fuzz> it gave me an a.out 1MB in size!
>
> That seems about right.  You have to include all of the Perl engine
> to make it work.
>
> What were you actually trying to do?
>
I think he thought it was going to automagically change it to a "C" program
and compile it. He probably didn't understand that the Perl engine needs to
go along with it.

Bob




------------------------------

Date: Mon, 21 Jul 2003 13:41:55 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Please critique my 2nd Perl program (generates an auction description)
Message-Id: <vhok3rh95s7502@corp.supernews.com>

In the spirit of laziness, impatience, and hubris, I set out to create my
own tool for creating the html portion of my eBay auctions; you know, the
part that one generally types or pastes into the multiline "description"
box.

I was tired of spending half my auction set-up time retyping the same thing,
and calling up the same html tags again and again.

The utility pasted in below creates a very simple auction template and fills
it in with whatever stuff the user desires.  It prompts for input, and
writes out an html file that can have its contents pasted into an eBay
auction description text box.  The outfile will appear in cwd as
auction.html.

You can get the rest by looking at the pasted utility below.

I am hoping for comments, suggestions, stylistic critiques, and a few hints.
As it stands now the utility works.  But it's not pretty.  The biggest
motivation in doing it was to become a little more proficient in Perl, which
is why I'm asking for comments.

I also wouldn't mind hearing suggestions on how to improve the text entery,
validity checking, user interface, flexibility, that sort of thing.

Thanks in advance.  ...kinda fun isn't it?

----------------------- pasted utility follows ----------------

bin/perl -w


# auctionwriter.pl
# This Perl appliction prompts for input of essential details, and outputs
# an HTML file that can be pasted into eBay's auction description.

# The application is intended to be a quick and easy way to formulate eBay
# auction descriptions.  It is assumed that the user understands a thing or
# two about eBay auctions.  This tool is not intended to compensate for a
# a lack of understandingof HTML or eBay, but rather, to be a shortcut for
# already-proficient eBay and HTML users.

# Validity checking of input is non-existant. It is encumbant upon the user
# to check his own work prior to listing an item.  This tool does provide a
# means to re-do the text of the auction, or to exit altogether, before the
# output file is written.

# Any html tags you include in your input will pass straight through to the
# final output document.

# The output file will appear in the cwd as auction.html.


# The auction's basic format will be as follows:
# 1. An <h1> centered headline.
# 2. An <h3> centered brief description.
# 3. One or more paragraphs containing a "teaser" -- an introduction to the
item.
# 4. A feature list (optional) in <DT> <DL> format.
# 5. One or more paragraphs containing the item's summary.
# 6. A paragraph containing the auction's details.
# 7. A series of zero or more <img src = ...> tags for auction pictures.



use strict;
use warnings;

# Declare the subroutines.
sub get_options;
sub get_headline;
sub get_subhead;
sub get_teaser;
sub get_features;
sub get_summary;
sub get_image_links;
sub create_html;
sub writeauction;


# Top level variables:
my ( %options,
  $headline,
  $subhead,
  @teaser,
  @features,
  @summary,
  @image_links,
  @document,
  $input );



# --- Begin main block ---

do {
 %options  = get_options();
 $headline  = get_headline();
 $subhead  =  get_subhead();
 @teaser   = get_teaser();
 @features  = get_features();
 @summary  = get_summary();
 @image_links = get_image_links();
 @document  = create_html( \%options,
          $headline,
          $subhead,
          \@teaser,
          \@features,
          \@summary,
          \@image_links );
 print "\nWrite html file, Redo input, or Quit? (w/r/q): ";
} until ( ( $input = <STDIN> ) !~ /^[rR]/ );
if ( $input =~ /^[qQ]/ ) {
 exit;
} else {
writeauction($options{"Output filename"},@document);
}
exit;

# --- End of main block ---





# *** NOTE ***
# This sub contains hardwired constants used as defaults.  While the user
can
# override the defaults at runtime, it is recommended that the defaults be
# edited within this source to more closely match the user's needs at time
# of installation of this application.  All hardwired constants are
# contained in the my declaration of %detail_hash.
# It should be unnecessary to look outside this function when changing
# default assumptions about the auction details.

sub get_options {
 my %options = (
   'Flat shipping cost', '$8.00',
   'Seller email address', 'email@address.com',
   # Image URL path should be a complete http:// path, minus the filename.
   'Image URL path',  'http://www.somewhere.com/~thisguy/auctions/',
   'Output filename',  'auction.html'
  );
 my ($input, $key);
 do {
  print "Current auction defaults:\n";
  foreach $key (sort keys %options) {
   print "$key: [$options{$key}]: ";
   chomp ( $input = <STDIN> );
   if ( $input ) {
    $options{$key} = $input;
   }
   print "\n";
  }
  print "Make additional changes? (y/n): ";
 } until ( <STDIN> =~ /^[nN]/ );
 print "\n\n";
 foreach $key (sort keys %options) {
  print "$key: $options{$key}.\n";
 }
 return %options;
}






sub get_headline {
 my $headline;
 print <<END_of_text;

Typically the auction headline is the name of the item being
sold, or a slightly longer version of the auction's line
listing. It will appear as a large, bold headline at the top
of the auction page.

END_of_text
 do {
  print "\nEnter auction headline.  Press [Enter] when done:\n";
  chomp ( $headline = <STDIN> );
  print "You entered:\n$headline\n";
  print "\nPress [Enter] to continue, or \"r\" to re-enter headline: ";
 } until ( <STDIN> !~ /^[rR]/ );
 return $headline;
}







sub get_subhead {
 my $subhead;
 print <<END_of_text;

The subhead is typically a two or three line brief elaboration
on the headline or auction title.  The idea is to build upon
the headline with just enough additional information to entice
bidders to read further.

END_of_text
 do {
  print "\nEnter auction subhead.  Press [Enter] when done:\n";
  chomp ( $subhead = <STDIN> );
  print "You entered:\n$subhead\n";
  print "Press [Enter] to continue, or \"r\" to re-enter headline: ";
 } until ( <STDIN> !~ /^[rR]/ );
 return $subhead;
}






sub get_teaser {
 my @teaser;
 print <<END_of_text;

The teaser is usually a one paragraph description of the item
being sold. It will preface a feature list, and is the seller's
opportunity to give a sales pitch.

The teaser will appear as plain text in most browsers.  If you
want any special text tricks such as italics or bold, you'll
have to do it yourself by entering the tags as you enter the text.

END_of_text
 do {
  print "\nEnter auction teaser. Press [Ctrl-D] to terminate text entry.\n";
  @teaser = <STDIN>;
  print "You entered: \n";
  foreach (@teaser) {
   print $_;
  }
  print "Press [Enter] to continue, or \"r\" to re-enter teaser: ";

 } until ( <STDIN> !~ /^[rR]/ );
 chomp @teaser;
 return @teaser;
}








sub get_features {
 my @featureset;
 print <<END_of_text;

Next you can enter a set of features for the item being
listed. These features will be listed as a bullet list.
Enter as many features as you like, or none at all. Keep
each feature short and sweet.  Think of features in terms
of their benefit to the potential bidder.

END_of_text
 do {
  print "\nEnter auction features.  Press [Ctrl-D] to terminate feature
entry.\n";
  @featureset = <STDIN>;
  print "You entered the following features: \n";
  foreach (@featureset) {
   print $_;
  }
  print "Press [Enter] to continue, or \"r\" to re-enter features: ";
 } until ( <STDIN> !~ /^[rR]/ );
 chomp @featureset;
 return @featureset;
}






sub get_summary {
 my @item_summary;
 print <<END_of_text;

In this section you may summarize the item being sold.
Be sure to describe condition, and anything else that
seems important that may have been left out about the item.

END_of_text
 do {
  print "\nEnter item summary. Press [Ctrl-D] to terminate text entry.\n";
  @item_summary = <STDIN>;
  print "You entered: \n";
  foreach (@item_summary) {
   print $_;
  }
  print "Press [Enter] to continue, or \"r\" to re-enter item summary: ";

 } until ( <STDIN> !~ /^[rR]/ );
 chomp @item_summary;
 return @item_summary;
}






sub get_image_links {
 my @images;
 print <<END_of_text;

Now you may enter the names of any image files that you wish
to display in conjunction with the auction.  All that is needed
is the filename, because you declared the HTTP path to the images
at the beginning of this process.  You may specify as many image
files as you wish, or none at all.

END_of_text
 do {
  print "Enter image filenames. Press [Ctrl-D] to terminate entry.\n";
  @images = <STDIN>;
  print "You entered: \n";
  foreach (@images) {
   print $_;
  }
  print "Press [Enter] to continue, or \"r\" to re-enter image filenames: ";

 } until ( <STDIN> !~ /^[rR]/ );
 chomp @images;
 return @images;
}









sub create_html {
 my ( $options,
   $headline,
   $subhead,
   $teaser,
   $features,
   $item_summary,
   $image_links  ) = @_;
 my @document;
 push ( @document, "<center><h1>$headline</h1></center><br>\n" );
 push ( @document, "<center><h3>$subhead</h3><br><hr></center><p>\n" );
 foreach ( @$teaser ) {
  push ( @document,"$_\n" );
 }
 push ( @document, "</p><p>Key features of this item:<br><ul>\n" );
 foreach ( @$features ) {
  push ( @document, "<li>$_\n" );
 }
 push ( @document, "</ul></p><p>\n" );
 foreach ( @$item_summary ) {
  push ( @document, "$_\n" );
 }
 push @document, <<END_text;
</p><hr><p>Winning bidder agrees to pay winning bid amount plus
$options->{"Flat shipping cost"}
to ship anywhere within the USA.  I'll only ship domestically, so US bidders
only please.
Payment may be via personal check or money order.  If payment is in the form
of a personal
check I'll ship after the check clears.  Serious bidders only.  I post
positive feedback
for all who deserve it, and negative feedback for abuses such as failure to
complete
the auction.  If you have any questions regarding this item or this auction,
please
contact me at <a href="mailto:$options->{"Seller email
address"}?subject=eBay Auction"><i>
$options->{"Seller email address"}</i></a>.</p>
<hr>
<center><h2>Happy bidding!</h2></center>

END_text
 foreach ( @$image_links ) {
  push ( @document, "<img src=\"$options->{'Image URL path'}$_\"><br>\n" );
 }
return @document;
}






sub writeauction {

 my ( $filename, @document ) = @_;
 if ( -e $filename ) {
  print "File already exists, overwrite? (y/n): ";
  if (<STDIN> !~ /^[yY]/) {
   print "Aborting file creation and exiting without saving changes.\n";
   exit;
  } elsif ( -w $filename ) {
   print "Unable to overwrite output file.  Check permissions.
Aborting.\n";
   exit;
  }
 }
 open (HTMLDOC, ">$filename" ) || die "Unable to open $filename for output.
$!\n";
 foreach ( @document ) {
  print HTMLDOC $_;
 }
 close (HTMLDOC) || die "Unable to close $filename. $!";
}




--
DJO




------------------------------

Date: Mon, 21 Jul 2003 18:05:46 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: push -- weird problem
Message-Id: <Xns93BF8F64C9244dkwwashere@216.168.3.30>

butt-fuzz <butt-fuzz@ass.wipe.com> wrote:

> i got a weird problem with push.
> 
> 
> for ($x=1;$x<=12;$x++){

C-style loops are usually not needed in Perl....

>     $sysDateLoop=`/usr/bin/cal $x 2003`;

The output of cal is in scalar context here. 

>     push @sysDate, $sysDateLoop;
>}
> $sysDate=join '##--Month-Break--##', @sysDate;
> this will produce jan, feb...dec. cals.

Yes, because each *month* is one array element.

> I tried a more lazy approach and I get weridness.
> for ($x=1;$x<=12;$x++){
>     push @sysDate `/usr/bin/cal $x 2003`;
                   ^
You're missing a comma in the push().

But assuming that's a typo (you should copy and paste working code), 
the problem is context.  

    push @sysDate, `/usr/bin/cal $x 2003`;

has `/usr/bin/cal $x 2003` in list context, so it puts each *line* of 
the cal output into a separate array element.  January 2003 (quoted 
text below) will be at least 7 array elements.

>}
> $sysDate=join '##--Month-Break--##', @sysDate;
> 
> look at this:
>     January 2003
> ##--Month-Break--##Su Mo Tu We Th Fr Sa 
> ##--Month-Break--##          1  2  3  4
> ##--Month-Break--## 5  6  7  8  9 10 11
> ##--Month-Break--##12 13 14 15 16 17 18
> ##--Month-Break--##19 20 21 22 23 24 25
> ##--Month-Break--##26 27 28 29 30 31


Force scalar context:

    push @sysDate, scalar `/usr/bin/cal $x 2003`;


More Perlishly, you can replace the entire loop with one line:

    push @sysDate, scalar `/usr/bin/cal $_ 2003` for (1..12);

Or if you prefer:

    for (1..12) {
        push @sysDate, scalar `/usr/bin/cal $_ 2003`;
    }



------------------------------

Date: Mon, 21 Jul 2003 14:15:24 -0400
From: butt-fuzz <butt-fuzz@ass.wipe.com>
Subject: Re: push -- weird problem
Message-Id: <3F1C2DBC.6E3EDB78@ass.wipe.com>



Eric Schwartz wrote:

sorry, I'm not a real programmer.
lots of stuff I don't understand even if I read the docs a hundred
times.
(only wrote code for less than one year)


------------------------------

Date: 21 Jul 2003 11:36:03 -0700
From: Patrick Flaherty <Patrick_member@newsguy.com>
Subject: Re: retrieve wishlist from Amazon
Message-Id: <bfhbqj0b9s@drn.newsguy.com>

Thanx Bob,

  That was a rather interesting exercise (got things workings).

Yes, Simon had mentioned that the id should be a combination of letters and
numbers.  However when I went orgiginally to what seemed to me should be the
right place (which is my wishlist listing itself), all I found was the numeric
string at the far right of the URL.

I figured, "ah maybe they've changed things (and Simon's procedure was written
in 2001)" so I went ahead and used that.

I did just now find a mixed numeria and alphabetic string but it was only by
clicking on 'Share your wishlist'.  And even then it was embedded in the middle
of the string, not on the far right.

Obviously there are subtlties to URLs that I'm not completely familiar with yet.

Anyway, this retrieves the contents of my wishlist (poorly formatted as you
pointed out).

  The first simplest formatting would look as follows:

> use WWW::Amazon::Wishlist qw(get_list);
> 
>   my @wishlist;
>   # my $my_amazon_com_id = "102-7528845-9327354";
>   my $my_amazon_com_id = "CORRECT ALPHANUMERIC STRING";
> 
>   @wishlist = get_list ($my_amazon_com_id);       # gets it from amazon.com
> 
> 
>   # the elements of @wishlist are hashrefs that contain ...
>   foreach my $book (@wishlist)
>   {
> print "$book->{title}\n",   # the, err, title
>       "$book->{author}\n",  # and the author(s) 
>       "$book->{asin}\n",    # the asin number, its unique id on Amazon
>       "$book->{price}\n",   # how much it will set you back
>       "$book->{type}\n\n";    # Hardcover/Paperback/CD/DVD etc
> 
>   }

However this leads to the observation (error) that author is no longer parsed
correctly (maybe Amazon has changed how this is laid out).  Do you see author
appearing correctly in the output?

  pat



In article <3F1B2B3D.5010807@rochester.rr.com>, Bob says...
>
>Patrick Flaherty wrote:
>
>...
>>   Would like to use Perl to retrive my wishlist periodically from Amazon.
>> 
>>Checked CPAN and there's actually a module to do this: WWW::Amazon::Wishlist
>> 
>>Written by someone in the UK so I had to modify it slightly.  Did so and tried
>> but then realized that it wasn't logging into my account (maybe this didn't
>> exist in 2001 when the script was first written).
>> 
>...
>
>
>>>  my $my_amazon_com_id = "002-1656974-7132841";
>
>
>You picked the wrong bit for your wish list ID.  It is the string that 
>has the mixed numbers and cap letters that you want.  And no, you don't 
>need to log in to look at someone's wish list.  And, I didn't have to 
>modify WWW::Amazon::Wishlist.pm (version 0.9).
>
>The following, for example, gets my wish list, although not very nicely 
>formatted:
>
>  use WWW::Amazon::Wishlist qw(get_list);
>  my @wishlist;
>  $my_amazon_com_id='3YBOF9YU9Q1E';
>  @wishlist = get_list ($my_amazon_com_id);       # gets it from amazon.com
>  # the elements of @wishlist are hashrefs that contain ...
>  foreach my $book (@wishlist)
>  {
>print $book->{title},   # the, err, title
>      $book->{author},  # and the author(s) 
>      $book->{asin},    # the asin number, its unique id on Amazon
>$book->{price},# how much it will set you back
>      $book->{type};    # Hardcover/Paperback/CD/DVD etc
>  }
>
>...
>
>
>>>  pat
>...
>
>-- 
>Bob Walton
>



------------------------------

Date: 21 Jul 2003 21:21:11 GMT
From: Tina Mueller <usenet@expires082003.tinita.de>
Subject: Re: See y'all in Paris?  YAPC::Europe::2003
Message-Id: <bfhlg7$etd1g$1@ID-24002.news.uni-berlin.de>

Brian McCauley wrote:
> Any of the other regulars here going to YAPC::Europe::2003 this week?

i'm not really a regular, but hey - i made it into the weekly
statistics last week =)

at the last german perl-workshop we had a meeting of
de.comp.lang.perl.* at one of the coffee-breaks;
i thought that was a nice idea.

tina
-- 
http://www.tinita.de/     \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/   \     / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/   \    \ _,_\ __/\ __/_| /__/ perception
- my mail address expires end of august 2003 -


------------------------------

Date: Mon, 21 Jul 2003 12:08:10 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Variable reference
Message-Id: <slrnbho7fq.eeb.tadmc@magna.augustmail.com>

Par <paer_nystroem@hotmail.com> wrote:

> I have a lot of variables in the form of
> $var{$something} = "Some text";
> 
> $something consists of two parts though. Ideally I would have liked it
> to be in the form of $var{$part1$part2}, but that doesn't work...
> So the really nasty looking part I've had to add is
> $something = $part1 . $part2;
> 
> So my question is basically how I avoid having the above line?!


   $var{ $part1 . $part2 }
or
   $var{ "$part1$part2" }


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Mon, 21 Jul 2003 17:10:13 -0400
From: Shawn Corey <shawn@magma.ca>
Subject: Re: Variable reference
Message-Id: <70KdneIRcb-8y4GiXTWJiQ@magma.ca>

Hi,

You should use $var{ $a, $b } = "Some text";
The key would be $a . $; . $b
$; is set to \034 but you can change it to any character you like.

This is an example to print the keys and values.
for my $key ( keys %var ){
   my ( $a, $b ) split /$;/, $key;
   print "key $a, $b has value $var{ $key }\n"
}

Jeff 'japhy' Pinyan wrote:

> On 21 Jul 2003, Par wrote:
> 
> 
>>$var{$something} = "Some text";
>>
>>$something consists of two parts though. Ideally I would have liked it
>>to be in the form of $var{$part1$part2}, but that doesn't work...
>>So the really nasty looking part I've had to add is
>>$something = $part1 . $part2;
>>
>>So my question is basically how I avoid having the above line?!
> 
> 
> Just do
> 
>   $var{$part1 . $part2}
> 
> or
> 
>   $var{"$part1$part2"}
> 



------------------------------

Date: 21 Jul 2003 21:19:46 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Variable reference
Message-Id: <bfhldi$6hf$1@nets3.rz.RWTH-Aachen.DE>

[ Please don't top-post; 
  your reply should come after the original text ]
  
Also sprach Shawn Corey:

> You should use $var{ $a, $b } = "Some text";
> The key would be $a . $; . $b
> $; is set to \034 but you can change it to any character you like.
> 
> This is an example to print the keys and values.
> for my $key ( keys %var ){
>    my ( $a, $b ) split /$;/, $key;
>    print "key $a, $b has value $var{ $key }\n"
> }

While the above is certainly right from a technical standpoint, I
stumbled over your first sentence:

    > You should use $var{ $a, $b } = "Some text";

I think this misses the point of the OP. He was essentially just asking
how to concatenate two strings to one hash-key. Using $hash{ LIST }
however is a Perl4ism. In a time when references weren't yet there, Perl
needed a way to work with multidimensional data-structures. Joining the
elements of the list together with $; was therefore just a work-around.
Nowadays fortunately perl knows about references and thus the
multidimensional array emulation is no longer needed.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


------------------------------

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



------------------------------

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 5252
***************************************


home help back first fref pref prev next nref lref last post