[28506] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9870 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 20 09:05:46 2006

Date: Fri, 20 Oct 2006 06:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 20 Oct 2006     Volume: 10 Number: 9870

Today's topics:
    Re: Eliminating required fields in perl script for iis  <zen13097@zen.co.uk>
    Re: FTP to a windows file share? <mattjones@hotmail.co.uk>
    Re: FTP to a windows file share? <bwilkins@gmail.com>
    Re: how to do programming in perl in windows <bwilkins@gmail.com>
    Re: Matching umlauts <fritz-bayer@web.de>
    Re: Matching umlauts <mritty@gmail.com>
    Re: Matching umlauts <rvtol+news@isolution.nl>
        new CPAN modules on Fri Oct 20 2006 (Randal Schwartz)
    Re: Parsing and regex <bol@adv.magwien.gv.at>
        Scripting an EXE <JKGambhir@gmail.com>
    Re: Scripting an EXE <bik.mido@tiscalinet.it>
    Re: Scripting an EXE <JKGambhir@gmail.com>
    Re: Scripting an EXE <josef.moellers@fujitsu-siemens.com>
    Re: Scripting an EXE (reading news)
    Re: Scripting an EXE <JKGambhir@gmail.com>
    Re: Scripting an EXE <josef.moellers@fujitsu-siemens.com>
        Tie, dbmopen and hashes <january.weiner@gmail.com>
    Re: Tie, dbmopen and hashes <mark.clementsREMOVETHIS@wanadoo.fr>
        Validating a file name <sicsicsic@freesurf.ch>
    Re: Validating a file name <ynl@nsparks.net>
    Re: Validating a file name <dlamber45@comcast.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 20 Oct 2006 08:19:11 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: Eliminating required fields in perl script for iis 6.0 server
Message-Id: <4538867f$0$21349$db0fefd9@news.zen.co.uk>

birdfludeathclock@yahoo.com <birdfludeathclock@yahoo.com> wrote:
> 
--<snip>--

You should 
  use strict;
  use warnings;

at the beginning of your script, so that perl will help you find your
problems.


>  #read standard input (HTTP server CGI)
>  read (STDIN, $input, $ENV{'CONTENT_LENGTH'}) or death("Can't read STDIN
>  from WWW server!",3,20);
>  @parse = split(/&/,$input);
> 
>  #Find FormDb Number to use
>  foreach $item (@parse)
>  {
>  	#Split pairs, remove URL formatting
>  	($name, $data) = split(/=/,$item,2);
>  	$data =~ tr/+/ /;
>  	$data =~ s/%(..)/pack("c",hex($1))/ge;
>  	$name =~ tr/+/ /;
>  	$name =~ s/%(..)/pack("c",hex($1))/ge;

If this is (as it appears to be) a CGI script, then don't roll your
own parsing code - use the proper tools:
    use CGI;


>  if($formdb eq undef) { death("Couldn't get FormDb Number!!",3,40); }

That's not how you check for an undefined value:
    if (not defined $formdb) ...


>  #Clean up memory used to read from STDIN
>  undef $input;

If you want your variables to go away, use proper scoping:

    {
	my $input;
	# ... do something with $input
    }
    # $input no longer exists

See: http://perl.plover.com/FAQs/Namespaces.html 


>  		#Is it a required field? (marked !...)
>  		if(index($name,"!") eq 0)

The operators 'ne', 'eq', 'gt', and 'lt' are for textual comparisons
Use '==', '!=', '>', and '<'  etc for numeric comparisons

		if ( index($name, '!') == 0 ) ...

>  		#Remove CR and LF from $data
>  		$data =~ tr/\x0A/ /;
>  		$data =~ tr/\x0D/ /;

That doesn't remove those characters - it changes them to spaces.

		$data =~ s/[\x0a\x0d]//g;


>  #Check for missing data
>  if(%DBFIELD eq undef) { death("No DB Field Data!!! How did that
>  happen??",3,1040); }

What do you think this is doing? 
To see if a hash is empty you could do:
    if (keys %DBFIELD == 0) ...
or even:
    if (%DBFIELD == 0) ... 

> 
>  open(DBREF, $refdb) or death("Could not open REF DBF during DB
>  create!",2,1130);

Better to use lexical filehandles, use the 3-argument form of open and
to include the failure reason ($!) in the error message:

    open my $dbref, '<', $refdb or die("open failed : $!");


>  $dbrcount++;
>  $dbrcount++;
>  $dbrcount++;
>  $dbrcount++;

    $dbrcount += 4

>  			#Strip out any none numeric values, replace with "0", leave dashs
>  "-" and decimals "."
>  			$DBFIELD{$fname} =~ tr/\x00-\x2C/\x30/;
>  			$DBFIELD{$fname} =~ tr/\x2F/\x30/;
>  			$DBFIELD{$fname} =~ tr/\x3A-\xFF/\x30/;


	$DBFIELD{$fname} =~ s/[^0-9.-]/0/g


>  				$dstack = join("",$dstack,$whole,".",$frac);

What's this obsession with join() ? Have you heard of the string
concatenation operator, "." ?

	$dstack = $dbstack . $whole . "." . $frac";

or better:

	$dstack .= "$whole.$frac";

>  	#Get current date/time info for file names and reporting
>  	($lsec,$lmin,$lhour,$lmday,$lmon,$lyear,$lwday,$lyday,$lisdst) =
>  localtime;
>  	$lmon++;
>  	$nowlocal = localtime;
>  	$nowgmt = gmtime;
>  	#Pad single digit numbers with a zero
>  	if(length($lsec) eq 1) { $lsec = join("","0",$lsec); }
>  	if(length($lmin) eq 1) { $lmin = join("","0",$lmin); }
>  	if(length($lhour) eq 1) { $lhour = join("","0",$lhour); }
>  	if(length($lmday) eq 1) { $lmday = join("","0",$lmday); }
>  	if(length($lmon) eq 1) { $lmon = join("","0",$lmon); }
>  	#Creat DB drop dir name
>  	$dump_dir = join("","IMPORT DB DATE ",($lyear +
>  1900),"-",$lmon,"-",$lmday," TIME ",$lhour,"-",$lmin,"-",$lsec);

Ouch!  Replace all that with:
	use POSIX;
	my $dump_dir = strftime "IMPORT DB DATE %Y-%m-%d TIME %H-%M-%S",
				localtime;
    

>  	#Could not make drop dir, idle for a bit then try again.
>  	if($doit < 5)
>  	{
>  		$tryout++;
>  		$idle = time;
>  		do { $wastecpu = time; } until $wastecpu ne $idle;
>  	}
>  	$doit++;

To wait for a second:
	sleep 1;

>  #Write out 490 bytes of 0x00 padding to close out header, total 512
>  byte header
>  $hloop = 0;
>  $pad = "";
>  do
>  {
>  	$pad = join ("",$pad,"\x00");
>  	$hloop++;
>  } until $hloop eq 490;

Again, Ouch!
    $pad = "\x00" x 490;


>  # &sendmail($from, $reply, $to, $smtp, $subject, $message );
>  #
> 
>  sub sendmail  {

Yuk!
If you're going to send mail, use one of the many existing modules
that are freely available on CPAN.

 

There are many things wrong with your code. I have only pointed out a
few of them. I hope my comments above will help you fix it (I'm glad I
don't have to do it!).




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

Date: 20 Oct 2006 03:25:51 -0700
From: "MattJ83" <mattjones@hotmail.co.uk>
Subject: Re: FTP to a windows file share?
Message-Id: <1161339951.753464.50850@b28g2000cwb.googlegroups.com>

hmm......
So if i just open the file (as above) - i can then transfer information
into it as normal?

I was under the impression i was going to have to use something like
Win32::NetResource

(im sorry - i don't think i said it was a windows server!).

The script currently transfers to unix servers by using &transfer
('server', 'username', 'password').

I need to connect to a windows server but the server won't let me log
on normally (policy of the server to not allow interactive login). So i
have to connect directly to the network resource (as you would map to a
drive). And then just allow the script to copy the information over to
the new loacation as well.



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

Date: 20 Oct 2006 05:18:15 -0700
From: "Brian  Wilkins" <bwilkins@gmail.com>
Subject: Re: FTP to a windows file share?
Message-Id: <1161346695.359082.245210@i42g2000cwa.googlegroups.com>


MattJ83 wrote:
> hmm......
> So if i just open the file (as above) - i can then transfer information
> into it as normal?
>
> I was under the impression i was going to have to use something like
> Win32::NetResource
>
> (im sorry - i don't think i said it was a windows server!).
>
> The script currently transfers to unix servers by using &transfer
> ('server', 'username', 'password').
>
> I need to connect to a windows server but the server won't let me log
> on normally (policy of the server to not allow interactive login). So i
> have to connect directly to the network resource (as you would map to a
> drive). And then just allow the script to copy the information over to
> the new loacation as well.

Somebody correct me if I am wrong, but can't he just execute a
exec("copy ...") within Perl? Would Perl even be useful for this task?
Why not a batch script?



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

Date: 20 Oct 2006 05:28:58 -0700
From: "Brian  Wilkins" <bwilkins@gmail.com>
Subject: Re: how to do programming in perl in windows
Message-Id: <1161347338.128590.173220@b28g2000cwb.googlegroups.com>


Sisyphus wrote:
> "Brian Wilkins" <bwilkins@gmail.com> wrote in message
> .
> .
> >
> > It must not be setup correctly on my machine then. It only works with
> > the C:/Perl/bin in the shebang.
> >
>
> I find that it's unnecessary to provide the shebang line, but if one *does*
> provide a shebang line, then that line must =~ /perl/i. But it doesn't need
> to relate in any way to the actual location of the perl executable:
>
> E:\>type try.pl
> print "OK";
> E:\>try.pl
> OK
> E:\>type try.pl
> #!Crap
> print "OK";
> E:\>try.pl
> Can't exec Crap at try.pl line 1.
>
> E:\>type try.pl
> #!Craperly
> print "OK";
> E:\>try.pl
> OK
> E:\>
>
> That's using perl 5.8.8 on Win32.
>
> Cheers,
> Rob

I'm used to CGI scripts. I just looked a perldoc perlrun and it states
that "If the #! line does not contain the word "perl", the program
named after the #! is executed instead of the Perl interpreter. This is
slightly bizarre, but it helps people on machines that don't do #!,
because they can tell a program that their SHELL is /usr/bin/perl, and
Perl will then dispatch the program to the correct interpreter for
them."

Apparently, there are machines that don't recognize the #! line also. I
never knew that. I have always been taught that the shebang line is
required.



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

Date: 20 Oct 2006 00:42:00 -0700
From: "fritz-bayer@web.de" <fritz-bayer@web.de>
Subject: Re: Matching umlauts
Message-Id: <1161330120.282688.313960@e3g2000cwe.googlegroups.com>


Paul Lalli wrote:
> fritz-bayer@web.de wrote:
> > I have to match words, which contains umlauts like =E4=F6=FC and also
> > french and other ones.
> >
> > Is there a way to use regular expressions in such a way that those get
> > treated like their normal corresponding letters?
> >
> > In other words, that "M=FCnchen" =3D "Munchen" when I do a pattern match
> > with =3D~ ?
>
> It is, in general, a really bad idea to simply pretend that one letter
> is another.  For an very basic example, the Spanish word "s=ED" means
> "yes", while the Spanish word "si" means "if".  They are different
> letters, and should be treated as such.

I agree.

>
> However, I don't think that's your actual question.  I think what you
> really want is to know if there's a way to make regexp special
> characters like \w expand its notion of what a "letter" is.  And the
> answer to that is "yes".   Simply enable locales in your script.
>

That is also interesting me. However, I was really looking for
something, where =FC and u are treated as equal matches.

> perldoc perllocale
> perldoc locale
>
> > Of course I could do all kinds of workarounds, but since there are many
> > of those characters, even from other countries, I was wondering if
> > there is some option, which will turn this on/off.
> >
> > Something like the "-i" switch for case in/sensitive searches.
>
> #!/opt2/perl/bin/perl
> use strict;
> use warnings;
> use locale;
> use POSIX qw(locale_h);
>
> $_ =3D "S=ED se=F1or!";
>
> print "Before locale in effect:\n";
> print "$1\n" while /(\w+)/g;
>
> setlocale(LC_CTYPE, "es_MX.ISO8859-1");
> print "After locale in effect:\n";
> print "$1\n" while /(\w+)/g;
> __END__
> Before locale in effect:
> S
> se
> or
> After locale in effect:
> S=ED
> se=F1or
>

I ran it and got

Before locale in effect:
S=ED
se=F1or
After locale in effect:
S=ED
se=F1or

Have you actually run the program?
>=20
> Paul Lalli



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

Date: 20 Oct 2006 03:36:08 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Matching umlauts
Message-Id: <1161340568.860575.182850@i42g2000cwa.googlegroups.com>

fritz-bayer@web.de wrote:
> Paul Lalli wrote:
> > #!/opt2/perl/bin/perl
> > use strict;
> > use warnings;
> > use locale;
> > use POSIX qw(locale_h);
> >
> > $_ =3D "S=ED se=F1or!";
> >
> > print "Before locale in effect:\n";
> > print "$1\n" while /(\w+)/g;
> >
> > setlocale(LC_CTYPE, "es_MX.ISO8859-1");
> > print "After locale in effect:\n";
> > print "$1\n" while /(\w+)/g;
> > __END__
> > Before locale in effect:
> > S
> > se
> > or
> > After locale in effect:
> > S=ED
> > se=F1or
> >
>
> I ran it and got
>
> Before locale in effect:
> S=ED
> se=F1or
> After locale in effect:
> S=ED
> se=F1or
>
> Have you actually run the program?

Yes.  I ran it and it produced the output I posted.  You apparently
already have locales enabled via an environment variable.

Paul Lalli



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

Date: Fri, 20 Oct 2006 13:16:59 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Matching umlauts
Message-Id: <ehaids.1dg.1@news.isolution.nl>

Josef Moellers schreef:

> Outside of Germany, "ü" may very well be "u", e.g. in Dutch (Ruud,
> please correct me if I'm wrong) "ü" would mean "a _u_ even if it would
> otherwise be coerced to the previous letter" ("reunie" might be
> pronounced differently from "reünie").


Yes, in Dutch, the double-dot is a diaeresis (trema), not an umlaut
mark.
But in loanwords and names from other languages it can of course be an
umlaut.

We spell München as "Munchen", but "Muunchjen" (read as Dutch) would be
closer to the actual pronounciation.

Compare English: zoölogic, coöperate, reënact, Chloë, Zoë.
http://en.wikipedia.org/wiki/Diaeresis_(diacritic)

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Fri, 20 Oct 2006 04:42:08 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Fri Oct 20 2006
Message-Id: <J7F3q8.qG1@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Alien-wxWidgets-0.23
http://search.cpan.org/~mbarbon/Alien-wxWidgets-0.23/
building, finding and using wxWidgets binaries
----
Astro-SpaceTrack-0.025
http://search.cpan.org/~wyant/Astro-SpaceTrack-0.025/
Retrieve orbital data from www.space-track.org.
----
BatchSystem-SBS-0.05
http://search.cpan.org/~alexmass/BatchSystem-SBS-0.05/
a Simple Batch System
----
CGI-WebIn-2.03
http://search.cpan.org/~koterov/CGI-WebIn-2.03/
Perl extension for reading CGI form data
----
CGI-WebOut-2.24
http://search.cpan.org/~koterov/CGI-WebOut-2.24/
Perl extension to handle CGI output (in PHP-style).
----
Cache-FastMmap-1.13
http://search.cpan.org/~robm/Cache-FastMmap-1.13/
Uses an mmap'ed file to act as a shared memory interprocess cache
----
Cache-FastMmap-1.14
http://search.cpan.org/~robm/Cache-FastMmap-1.14/
Uses an mmap'ed file to act as a shared memory interprocess cache
----
Catalyst-Plugin-PageCache-0.13
http://search.cpan.org/~agrundma/Catalyst-Plugin-PageCache-0.13/
Cache the output of entire pages
----
Catalyst-Plugin-PageCache-0.14
http://search.cpan.org/~agrundma/Catalyst-Plugin-PageCache-0.14/
Cache the output of entire pages
----
Config-Model-0.603
http://search.cpan.org/~ddumont/Config-Model-0.603/
Model to create configuration validation tool
----
Crypt-Camellia-2.01
http://search.cpan.org/~oyama/Crypt-Camellia-2.01/
Perl Camellia encryption module
----
Crypt-Pwsafe-1.002
http://search.cpan.org/~tangent/Crypt-Pwsafe-1.002/
Perl extension for decrypting and parsing PasswordSafe V3 data files
----
DBD-InterBase-0.45
http://search.cpan.org/~edpratomo/DBD-InterBase-0.45/
DBI driver for Firebird and InterBase RDBMS server
----
Data-SimplePassword-0.02
http://search.cpan.org/~ryochin/Data-SimplePassword-0.02/
Simple random password generator
----
Email-MIME-1.855
http://search.cpan.org/~rjbs/Email-MIME-1.855/
Easy MIME message parsing.
----
Email-Simple-1.995
http://search.cpan.org/~rjbs/Email-Simple-1.995/
Simple parsing of RFC2822 message format and headers
----
Genezzo-0.65
http://search.cpan.org/~jcohen/Genezzo-0.65/
an extensible database with SQL and DBI
----
Google-Adwords-v0.5.1
http://search.cpan.org/~rohan/Google-Adwords-v0.5.1/
an interface which abstracts the Google Adwords SOAP API
----
HTTP-Server-Simple-0.21
http://search.cpan.org/~jesse/HTTP-Server-Simple-0.21/
Lightweight HTTP server
----
HTTP-Server-Simple-0.22
http://search.cpan.org/~jesse/HTTP-Server-Simple-0.22/
Lightweight HTTP server
----
Lingua-EL-Poly2Mono-0.02
http://search.cpan.org/~sprout/Lingua-EL-Poly2Mono-0.02/
Convert polytonic Greek to monotonic
----
Mail-SpamCannibal-0.78
http://search.cpan.org/~miker/Mail-SpamCannibal-0.78/
A tool to stop SPAM
----
Net-Bind-rbldnsdAccessor-0.04
http://search.cpan.org/~miker/Net-Bind-rbldnsdAccessor-0.04/
access rbldnsd files with Perl or BIND
----
Net-DNS-ToolKit-0.30
http://search.cpan.org/~miker/Net-DNS-ToolKit-0.30/
tools for working with DNS packets
----
Net-SC-1.20
http://search.cpan.org/~gosha/Net-SC-1.20/
perl module for create the chain from the SOCKS/HTTP proxies.
----
Parse-DMIDecode-0.01
http://search.cpan.org/~nicolaw/Parse-DMIDecode-0.01/
Interface to SMBIOS under Linux using dmidecode
----
Pod-WSDL-0.05
http://search.cpan.org/~tareka/Pod-WSDL-0.05/
Creates WSDL documents from (extended) pod
----
Test-CheckManifest-0.4
http://search.cpan.org/~reneeb/Test-CheckManifest-0.4/
Check if your Manifest matches your distro
----
Test-Class-0.20
http://search.cpan.org/~adie/Test-Class-0.20/
Easily create test classes in an xUnit/JUnit style
----
Test-LongString-0.10
http://search.cpan.org/~rgarcia/Test-LongString-0.10/
tests strings for equality, with more helpful failures
----
Wx-0.58
http://search.cpan.org/~mbarbon/Wx-0.58/
interface to the wxWidgets cross-platform GUI toolkit
----
Wx-TreeListCtrl-0.05
http://search.cpan.org/~mwardell/Wx-TreeListCtrl-0.05/
interface to the Wx::TreeListCtrl class
----
XML-RSS-1.11
http://search.cpan.org/~abh/XML-RSS-1.11/
creates and updates RSS files
----
classes-0.942
http://search.cpan.org/~rmuhle/classes-0.942/
conventional Perl 5 classes
----
go-perl-0.05
http://search.cpan.org/~cmungall/go-perl-0.05/
----
iCal-Parser-1.14
http://search.cpan.org/~rfrankel/iCal-Parser-1.14/
Parse iCalendar files into a data structure


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
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: Fri, 20 Oct 2006 08:52:59 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: Parsing and regex
Message-Id: <1161327179.837795@proxy.dienste.wien.at>

toof57:

> $Parse1="/^take me ([a-zA-Z0-9]+)\s(.*)/";

This can't work for 2 reasons:

x) First, when in double quotes, string interpolation will occur,
making the "\s" just to a "s". So use single quotes instead.

x) Second, Slashes are used as delimiters for regexes. If given
in a string, they become part of your regex. In other words, the
regex above looks (anywhere in the given string) for a slash,
followed by a caret, followed by "take me ", followed by one
more alphanumeric characters (which are grouped), followed
by a 's', optionally followed by any number of any characters
(which are grouped again).

I'd suggest to use the qr operator here. It allows you to write
the regex as-is, but without string interpolation:

$Parse1 = qr/^take me ([a-zA-Z0-9])+\s(.*)/;

perldoc perlre

should help.

Greetings, Ferry

-- 
Ing Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: bol@adv.magwien.gv.at




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

Date: 20 Oct 2006 00:05:08 -0700
From: "JKG" <JKGambhir@gmail.com>
Subject: Scripting an EXE
Message-Id: <1161327908.632092.21510@b28g2000cwb.googlegroups.com>

I have an EXE (say t2t2.exe), I do not have its source. It have the
following behaviour:
------------------------
C:\>t2t2.exe
Reading the temp files.
Reading done.
Writing the temp files.
Writing done.
Please enter option (1..9)=> 2
You entered 2.
File processing done.
C:\>
------------------------
There are 9 options that can be passed. But I always passes 2 and I do
it several times a day.
I want to write a perl script for this. I think perl pipes will help.
But I dont know how to start.
Any HELP?



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

Date: 20 Oct 2006 09:36:07 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Scripting an EXE
Message-Id: <blugj2lesj5adqogijl722spo2f3c62up4@4ax.com>

On 20 Oct 2006 00:05:08 -0700, "JKG" <JKGambhir@gmail.com> wrote:

>I have an EXE (say t2t2.exe), I do not have its source. It have the
>following behaviour:
[snip]
>I want to write a perl script for this. I think perl pipes will help.
>But I dont know how to start.
>Any HELP?

Hard to say anything without knowing what t2t.exe does. Indeed your
phrasing may seem to suggest the idea that you want to rewrite it. If,
as is more probable, you just want to *call* it, then if you don't
care to gather the program's output, a simple open() may do. Read

  perldoc -f open

and look for '|-'. Otherwise you may need IPC::Open2 or IPC::Open2, or
Expect.pm.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 20 Oct 2006 01:30:14 -0700
From: "JKG" <JKGambhir@gmail.com>
Subject: Re: Scripting an EXE
Message-Id: <1161333010.510722.216310@m73g2000cwd.googlegroups.com>

Thanks for the reply.

> Hard to say anything without knowing what t2t.exe does.
I think I should provide more details about the EXE. When I execute
this EXE, it reads some predefined temp files (these temp files
contains list of prime numbers). Then it asks for user input. When I
press option 2, it finds the next prime number and add it into the
predifined file.
I never used any other option except option 2.

My requirement is to write a perl script that passes the option 2 to
the EXE, when the EXE ask for it.

I am studying the perldoc (pipes and IPC).
Still a peice of code in this reply will help me a lot.

Thanks again.

Michele Dondi wrote:
> On 20 Oct 2006 00:05:08 -0700, "JKG" <JKGambhir@gmail.com> wrote:
>
> >I have an EXE (say t2t2.exe), I do not have its source. It have the
> >following behaviour:
> [snip]
> >I want to write a perl script for this. I think perl pipes will help.
> >But I dont know how to start.
> >Any HELP?
>
> Hard to say anything without knowing what t2t.exe does. Indeed your
> phrasing may seem to suggest the idea that you want to rewrite it. If,
> as is more probable, you just want to *call* it, then if you don't
> care to gather the program's output, a simple open() may do. Read
>
>   perldoc -f open
>
> and look for '|-'. Otherwise you may need IPC::Open2 or IPC::Open2, or
> Expect.pm.
>
>
> Michele
> --
> {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
> (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
> .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
> 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,



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

Date: Fri, 20 Oct 2006 10:29:40 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Scripting an EXE
Message-Id: <eha1hv$7q2$1@nntp.fujitsu-siemens.com>

JKG wrote:
> I have an EXE (say t2t2.exe), I do not have its source. It have the
> following behaviour:
> ------------------------
> C:\>t2t2.exe
> Reading the temp files.
> Reading done.
> Writing the temp files.
> Writing done.
> Please enter option (1..9)=3D> 2
> You entered 2.
> File processing done.
> C:\>
> ------------------------
> There are 9 options that can be passed. But I always passes 2 and I do
> it several times a day.
> I want to write a perl script for this. I think perl pipes will help.
> But I dont know how to start.

Why can't a simple "echo 2 | t2t2.exe" (or the DOS equivalent) do the wor=
k?
If you need to parse some feedback, there's Perl/Expect, but I don't=20
know if that runs on your system.

Just wanting to help,

Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: Fri, 20 Oct 2006 08:35:21 GMT
From: "Mumia W. (reading news)" <paduille.4060.mumia.w@earthlink.net>
Subject: Re: Scripting an EXE
Message-Id: <dT%Zg.16269$UG4.2353@newsread2.news.pas.earthlink.net>

On 10/20/2006 02:05 AM, JKG wrote:
> I have an EXE (say t2t2.exe), I do not have its source. It have the
> following behaviour:
> ------------------------
> C:\>t2t2.exe
> Reading the temp files.
> Reading done.
> Writing the temp files.
> Writing done.
> Please enter option (1..9)=> 2
> You entered 2.
> File processing done.
> C:\>
> ------------------------
> There are 9 options that can be passed. But I always passes 2 and I do
> it several times a day.
> I want to write a perl script for this. I think perl pipes will help.
> But I dont know how to start.
> Any HELP?
> 

Maybe this will work:

C:\> echo "2" | t2t2.exe

Or you could use Expect.pm.


-- 
paduille.4060.mumia.w@earthlink.net


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

Date: 20 Oct 2006 01:45:13 -0700
From: "JKG" <JKGambhir@gmail.com>
Subject: Re: Scripting an EXE
Message-Id: <1161333913.572676.145950@h48g2000cwc.googlegroups.com>

Hi Thanks a lot for the help.

> Why can't a simple "echo 2 | t2t2.exe" (or the DOS equivalent) do the wor=
k?
Yes your suggestion it good and it worked to some point.
Actually it is my mistake to explain the behaviour of the EXE properly.
I am explaining it again:
 ------------------------
C:\>t2t2.exe
Reading the temp files.
Reading done.
Writing the temp files.
Writing done.
Please enter option (1..9 or q)=3D> 2
You entered 2.
File processing done.
Please enter option (1..9 or q)=3D>q
Quit......bye
C:\>
------------------------
Means after providing option 2, I have to provide option q also to quit
from the EXE.

I tried the following command as per your suggestion:
C:\>echo 2 | t2t2.exe
but then the EXE is running in the infinite loop reading option 2
everytime. I just want this EXE to run once for option 2 and then quit
(reads option q).

Please help....I think you are toooooooo close.


Josef Moellers wrote:
> JKG wrote:
> > I have an EXE (say t2t2.exe), I do not have its source. It have the
> > following behaviour:
> > ------------------------
> > C:\>t2t2.exe
> > Reading the temp files.
> > Reading done.
> > Writing the temp files.
> > Writing done.
> > Please enter option (1..9)=3D> 2
> > You entered 2.
> > File processing done.
> > C:\>
> > ------------------------
> > There are 9 options that can be passed. But I always passes 2 and I do
> > it several times a day.
> > I want to write a perl script for this. I think perl pipes will help.
> > But I dont know how to start.
>
> Why can't a simple "echo 2 | t2t2.exe" (or the DOS equivalent) do the wor=
k?
> If you need to parse some feedback, there's Perl/Expect, but I don't
> know if that runs on your system.
>
> Just wanting to help,
>
> Josef
> --
> Josef M=F6llers (Pinguinpfleger bei FSC)
> 	If failure had no penalty success would not be a prize
> 						-- T.  Pratchett



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

Date: Fri, 20 Oct 2006 13:05:44 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Scripting an EXE
Message-Id: <ehaao7$9ld$1@nntp.fujitsu-siemens.com>

JKG wrote:
> Hi Thanks a lot for the help.
>=20
>=20
>>Why can't a simple "echo 2 | t2t2.exe" (or the DOS equivalent) do the w=
ork?
>=20
> Yes your suggestion it good and it worked to some point.
> Actually it is my mistake to explain the behaviour of the EXE properly.=

> I am explaining it again:
>  ------------------------
> C:\>t2t2.exe
> Reading the temp files.
> Reading done.
> Writing the temp files.
> Writing done.
> Please enter option (1..9 or q)=3D> 2
> You entered 2.
> File processing done.
> Please enter option (1..9 or q)=3D>q
> Quit......bye
> C:\>
> ------------------------
> Means after providing option 2, I have to provide option q also to quit=

> from the EXE.
>=20
> I tried the following command as per your suggestion:
> C:\>echo 2 | t2t2.exe
> but then the EXE is running in the infinite loop reading option 2
> everytime. I just want this EXE to run once for option 2 and then quit
> (reads option q).
>=20
> Please help....I think you are toooooooo close.

Strange behaviour (re-using "2" over and over again).
On *ix systems I'd do something like '(echo 2; echo q) | t2t2' or
'echo -e "2\nq" | t2t2'.
You could write a Perl program:

print "2\rq\r";

Josef

> Josef Moellers wrote:
>=20
>>JKG wrote:
>>
>>>I have an EXE (say t2t2.exe), I do not have its source. It have the
>>>following behaviour:
>>>------------------------
>>>C:\>t2t2.exe
>>>Reading the temp files.
>>>Reading done.
>>>Writing the temp files.
>>>Writing done.
>>>Please enter option (1..9)=3D> 2
>>>You entered 2.
>>>File processing done.
>>>C:\>
>>>------------------------
>>>There are 9 options that can be passed. But I always passes 2 and I do=

>>>it several times a day.
>>>I want to write a perl script for this. I think perl pipes will help.
>>>But I dont know how to start.
>>
>>Why can't a simple "echo 2 | t2t2.exe" (or the DOS equivalent) do the w=
ork?
>>If you need to parse some feedback, there's Perl/Expect, but I don't
>>know if that runs on your system.
>>
>>Just wanting to help,
>>
>>Josef
>>--
>>Josef M=F6llers (Pinguinpfleger bei FSC)
>>	If failure had no penalty success would not be a prize
>>						-- T.  Pratchett
>=20
>=20
>=20


--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: Fri, 20 Oct 2006 12:16:44 +0200 (CEST)
From: January Weiner <january.weiner@gmail.com>
Subject: Tie, dbmopen and hashes
Message-Id: <eha7mc$3u$1@sagnix.uni-muenster.de>

Hi all,

I have a large flatfile (we are talking gigabytes here) with records which
I need to access randomly.  I have tried different approaches (e.g. using
SQL), and what seems to work fastest is a simple dbmopen() with a hash that
holds the respective keys (e.g. record IDs) and, as values, the positions
in the file.  Here is a sample code used for indexing:

# ----------------------------------------------------
#!/usr/bin/perl
# db formatter

my $file = 'flatfile.txt' ;

my %pos_hash ;
dbmopen( %pos_hash, $file . '.idx', 0666 ) ;

my $if ;
my $tell_pos = 0 ;

open( $if, '<flatfile.txt') || die "Cannot open $file: $!\n" ;

while(<$if>) {
  if( substr($_, 0, 3 ) eq 'REC' ) {
    /REC\s*(\S+)/ ;              # records start with 'REC'
    $pos_hash{$1} = $tell_pos ;
  }

  $tell_pos = tell( $if ) ;
}

close( $if ) ;
dbmclose( %pos_hash ) ;

# ----------------------------------------------------

And here is a sample code used for accessing the records:

# ----------------------------------------------------
#!/usr/bin/perl
# db reader

my $file = 'flatfile.txt' ;
my $record = 'id89781827376' ;

my %pos_hash ;
dbmopen( %pos_hash, $file . '.idx', 0444 ) ;

my $if ;
my $tell_pos = 0 ;

open( $if, '<flatfile.txt') || die "Cannot open $file: $!\n" ;

$tell_pos = $pos_hash{$record} ; # position of the record
seek( $if, $tell_pos, 0 ) ;      # go to the specific position

my $line = <$if> ; # read  the first record field
print $line      ; # print the first record field

while( <$if> ) {
  last if( substr( $_, 0, 3 ) eq 'REC' ) ; # next record
  print $_ ;
}

close( $if ) ;
dbmclose( %pos_hash ) ;

# ----------------------------------------------------


I have two questions:

1) I find that two programs cannot open the database at the same time. Is
   this correct, even though I set the permissions to "read only" (0444)?  

2) At first, I wanted to use "tie". However, the documentation I read is
   mostly about creating new classes, and I did not understand much from
   it.  Is there a way of using "tie" which would behave as a simple
   dbmopen, and if yes, (i) where can I read about it and (ii) what
   advantages will it give me?

Regards,

January

-- 


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

Date: Fri, 20 Oct 2006 14:24:14 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Tie, dbmopen and hashes
Message-Id: <4538bfe6$0$5103$ba4acef3@news.orange.fr>

January Weiner wrote:
> Hi all,
> 
> I have a large flatfile (we are talking gigabytes here) with records which
> I need to access randomly.  I have tried different approaches (e.g. using
> SQL), and what seems to work fastest is a simple dbmopen() with a hash that
> holds the respective keys (e.g. record IDs) and, as values, the positions
> in the file.  Here is a sample code used for indexing:

This is a personal opinion - I have no doubt that many posters here will 
not agree with me:

With that much data I'd argue you'd be better off injecting the data 
into an RDBMS and working on it from there. If you don't have a suitable 
RDBMS to hand and can't justify the overhead of installing one, even a 
lightweight solution like SQLite would probably be preferable to 
manipulating the file manually.

see

DBD::SQLite
www.sqlite.org

Mark


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

Date: Fri, 20 Oct 2006 14:32:01 +0200
From: Philipp <sicsicsic@freesurf.ch>
Subject: Validating a file name
Message-Id: <1161347521_31@sicinfo3.epfl.ch>

Hello,
I want to create a file with a filename coming from a string (which I 
have no control over).
Is there a package to check if the string is valid as a filename on the 
OS (my case Win32)?

The package would check for:
  - invalid characters (: / \ ? etc)
  - control characters
  - length of string (max 215 chars on win32 I think)
etc.

I have not been able to find anything like that browsing the perl faq.

Thanks for your answers.
Phil


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

Date: Fri, 20 Oct 2006 14:56:50 +0200
From: Yohan N Leder <ynl@nsparks.net>
Subject: Re: Validating a file name
Message-Id: <MPG.1fa2e5fea3035a079898eb@news.tiscali.fr>

In article <1161347521_31@sicinfo3.epfl.ch>, sicsicsic@freesurf.ch 
says...
> I have not been able to find anything like that browsing the perl faq.
> 

http://search.cpan.org/~bch/Win32-Filenames-0.01/lib/Win32/Filenames.pm


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

Date: Fri, 20 Oct 2006 09:02:43 -0400
From: David Lee Lambert <dlamber45@comcast.net>
Subject: Re: Validating a file name
Message-Id: <pan.2006.10.20.13.02.42.276506@comcast.net>

On Fri, 20 Oct 2006 14:32:01 +0200, Philipp wrote:

> I want to create a file with a filename coming from a string (which I 
> have no control over).
> Is there a package to check if the string is valid as a filename on the 
> OS (my case Win32)?
> 
> The package would check for:
>   - invalid characters (: / \ ? etc)
>   - control characters
>   - length of string (max 215 chars on win32 I think)
> etc.
> 
> I have not been able to find anything like that browsing the perl faq.

Well,  the MS Tablet PC API accepts the following pattern for file-names:

* For file name, allows all IS_ONECHAR characters except: \ / : < > |

This is easy to test with regular expressions,  e.g.

  $fn_ok = ($fn =~ m!^[^\\/:<>|]+$! and $fn !~ m![\x00-\x1f\x7f-\x9f]!)

However,  in input validation,  it's generally better to test for
compliance with the rules rather than nondangerousness.  Something like
one of these would probably be better,  and more readable:

  $fn_ok - ($fn =~ m!^[a-z0-9 _+-]+$!i);  # ASCII alphanumeric, space,
                                          # hyphen, underline, plus
  
  $fn_ok = ($fn =~ m!^[0-9\pL-]$);  # Unicode letter, ASCII number, hyphen

-- 
PGP key posted on website ... http://www.lmert.com/people/davidl/



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9870
***************************************


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