[19554] in Perl-Users-Digest
Perl-Users Digest, Issue: 1749 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 14 18:10:43 2001
Date: Fri, 14 Sep 2001 15:10:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1000505415-v10-i1749@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 14 Sep 2001 Volume: 10 Number: 1749
Today's topics:
Need help please... <me_gill@hotmail.com>
Re: Need help please... (Logan Shaw)
Re: Need help please... <thomas@baetzler.de>
Re: Need help please... (Tad McClellan)
newbie question: membership script w/ credit card verif (Stephen)
Re: parsing large DNA files into smaller files <thomas@baetzler.de>
Re: parsing large DNA files into smaller files (Anno Siegel)
Re: parsing large DNA files into smaller files (Tad McClellan)
Re: parsing large DNA files into smaller files <nobody@no_where.net>
Re: Parsing problem (Please HELP ) (Ken Laird)
Re: Passing a parameter from a text file???? Big Thank <acoustic_bill@yahoo.com>
Re: Perl (slurping) is TOO much fun (Logan Shaw)
Re: Perl (slurping) is TOO much fun <uri@sysarch.com>
Re: Perl (slurping) is TOO much fun (Damian James)
perl command line flags <bruhwel@jlab.org>
Re: perl command line flags <thomas@baetzler.de>
Re: perl command line flags <mjcarman@home.com>
Re: perl command line flags (Tad McClellan)
Perl to MS SQL <shino_korah@yahoo.com>
Re: Perl to MS SQL <thomas@baetzler.de>
pipe to passwd <abatko@cs.mcgill.ca>
Re: pipe to passwd <thomas@baetzler.de>
Re: pipe to passwd <abatko@cs.mcgill.ca>
Re: pipe to passwd (Logan Shaw)
report duplicate ip addresses in file (Geoff Rothman)
Re: report duplicate ip addresses in file (Anno Siegel)
Re: report duplicate ip addresses in file <thomas@baetzler.de>
Urgently need help with Net::SSH::Perl / Math::Pari / @ <nobody@no_where.net>
Re: Urgently need help with Net::SSH::Perl / Math::Pari (Anno Siegel)
Re: use autouse 'Data::Dumper' => qw(Dump); (Anno Siegel)
Using Perl to post regular usenet messages. <overlord_q@hotmail.com>
Re: Using Perl to post regular usenet messages. <thomas@baetzler.de>
Re: Using Perl to post regular usenet messages. (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 14 Sep 2001 15:10:08 -0500
From: "Michael Gill" <me_gill@hotmail.com>
Subject: Need help please...
Message-Id: <3ba263e9@news.wworld.com>
Hi,
I don't know thing one about how to program Perl. I downloaded an HTTP File
Upload script that is written in Perl that I want to change just a little.
I've got the script running, but am hoping someone can help me out.
There is a variable in the file that you set to the URL you want to see
after a successful upload. This variable is declared at the beginning of
the code. What I'm wanting to do is set that variable equal to
"http://myserver.com/scripts/foxisapi.dll/server.enging.uploadcomplete?" +
FileNameVariable
The current code only allows for the part in quotes. Might someone be
willing to help?
Thanks,
Mike
------------------------------
Date: 14 Sep 2001 15:20:04 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Need help please...
Message-Id: <9ntopk$5ib$1@charity.cs.utexas.edu>
In article <3ba263e9@news.wworld.com>,
Michael Gill <me_gill@hotmail.com> wrote:
>the code. What I'm wanting to do is set that variable equal to
>"http://myserver.com/scripts/foxisapi.dll/server.enging.uploadcomplete?" +
>FileNameVariable
>The current code only allows for the part in quotes.
If I run this Perl code:
$foo = "abc";
$bar = "123";
$foo .= $bar;
print $foo;
I get "abc123" as the output.
Actually, though, in your case this is not the right thing to do,
because if that variable has funny characters in it that have a
special meaning in a URL (like "?", "&", and so on), then your
variable will contain the wrong URL to pass that information along.
So, you want to use something to escape those special characters.
Unfortunately, I'm not a big web programmer, so I don't know
what the proper technique is, but I know that there is at least
one module that does this for you. If your environment is set
up for web development, you may already have such a module
available. If not, you could probably download and install
URI::Escape. See http://search.cpan.org/search?dist=URI .
- Logan
--
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)
------------------------------
Date: Fri, 14 Sep 2001 22:48:44 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: Need help please...
Message-Id: <dtp4qtk6o6r6cqrbit6qsk5796r56di11q@4ax.com>
On Fri, 14 Sep 2001, "Michael Gill" <me_gill@hotmail.com> wrote:
>I don't know thing one about how to program Perl. I downloaded an HTTP File
>Upload script that is written in Perl that I want to change just a little.
Oh, you install CGI programs on your machine that you can't read
and/or understand? Could I have the ip address, please? :-P
Naaah, just kidding, of course, but you see where the problem lies?
>There is a variable in the file that you set to the URL you want to see
>after a successful upload. This variable is declared at the beginning of
>the code. What I'm wanting to do is set that variable equal to
>"http://myserver.com/scripts/foxisapi.dll/server.enging.uploadcomplete?" +
>FileNameVariable
>The current code only allows for the part in quotes. Might someone be
>willing to help?
I assume that "FileNameVariable" should be the file name of the file
being uploaded? Without knowledge of the upload script, we can but
guess as to what the variable name might be.
A previous poster already explained that any form data needs to be
properly encoded. Add "use URI::Escape;" in the top section of the
script - this will pull in the uri_escape() function.
If your script has a "use CGI;" statement at the top, you can try
this:
- check the upload HTML page and find the name of the upload HTML
element - i.e. look for "<INPUT TYPE="file" NAME="uploaded_file"" and
note NAME value, i.e. "uploaded_file".
- if there's an assignment like "my $query = new CGI;" (with or
without the "my"), note the variable name (i.e. $query).
Your text is now either
uri_escape( $query->param('uploaded_file') )
or - if the script doesn't use the OO interface to CGI.pm -
uri_escape( param('uploaded_file') )
with $query and uploaded_file are of course the values you have noted
down.
Your variable assignment should now look a bit like this
$whatever = "url_up_to_now?" . phrase_from_above ;
If the CGI script uses the OO interface, this assignment should appear
AFTER the "new CGI" assignment of the CGI object.
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 14 Sep 2001 21:37:37 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Need help please...
Message-Id: <slrn9q4qq7.kpp.tadmc@tadmc26.august.net>
Michael Gill <me_gill@hotmail.com> wrote:
>Subject: Need help please...
Need subject in Subject: please.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 14 Sep 2001 11:35:26 -0700
From: fjsaldi@hotmail.com (Stephen)
Subject: newbie question: membership script w/ credit card verification
Message-Id: <854dabf6.0109141035.a0a21a0@posting.google.com>
I'm working on a new site that requires a person to enroll and pay a
tuition fee online. Is there a script available that requests and
supports the following:
Name
Address
Username
password
credit card
Upon verification of the credit card, the user
is allowed access to the paid area of the site
(in this case, an online school)? It then sends
a receipt to the student and the information to
the company.
I've found a couple, but they all use iBill or something similar, and
I'd rather not use that.
Thanks for your help,
Stephen
------------------------------
Date: Fri, 14 Sep 2001 21:06:34 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: parsing large DNA files into smaller files
Message-Id: <ltk4qt4gomt36ber7cremv1dahmhapnjqg@4ax.com>
On Fri, 14 Sep 2001, "Jeff Gruen" <gruen.lab@yale.edu> wrote:
>I am a newbie to perl and unix script writing.
>I am looking for a script that will help us to parse a large DNA sequence
>file into smaller text files.
[...]
That way, you'll always stay a newbie - how'bout trying to do it
yourself first?
#!/usr/bin/perl -w
use strict;
# where's the input data?
my $infile = 'dna.seq';
# how many bases in each split?
my $splitsize = 10000;
open( IN, "$infile" )
or die "Can't open DNA file '$infile': $!\n";
for( my($pos,$data,$got)=(1); !eof( IN ); $pos += $got ){
# note: no slurping - instead ingestion via a small spoon
if( defined( $got = read IN, $data, $splitsize ) ){
my $file = "$pos\_" . ( $pos + $got - 1) . ".seq";
open( OUT, ">$file" )
or die "Can't open DNA file '$file': $!\n";
print( OUT ">$file\n$data\n" )
or die "Can't write to DNA file '$file': $!\n";
close( OUT );
} else {
die "read on '$infile' failed: $!\n";
}
}
__END__
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 14 Sep 2001 19:30:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: parsing large DNA files into smaller files
Message-Id: <9ntlsm$83j$2@mamenchi.zrz.TU-Berlin.DE>
According to Thomas Bätzler <thomas@baetzler.de>:
> # note: no slurping - instead ingestion via a small spoon
Cardinal Slurphammer will be pleased when I mention this.
Anno
------------------------------
Date: Fri, 14 Sep 2001 19:34:56 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: parsing large DNA files into smaller files
Message-Id: <slrn9q4k88.kdc.tadmc@tadmc26.august.net>
Jeff Gruen <gruen.lab@yale.edu> wrote:
>I am looking for a script that will help us to parse a large DNA sequence
>file into smaller text files.
>We would like to parse the larger file into non-overlapping smaller files of
>10,000 letters. Each file should contain it's own descriptive name, which
>would also be contained in the first line of the sequence file.
>Please note the ">" sign in the first position of the header.
----------------------------------
#!/usr/bin/perl -w
use strict;
my $size = 10;
my $lower = 1;
my $upper = $lower + $size - 1;
#open(DATA, ...
my $str; # string buffer
while ( my $bytes = read(DATA, $str, $size) ) {
my $fname = "${lower}_$upper.seq";
$lower += $size;
$upper += $size;
open(OUT, ">$fname") or die "could not open '$fname' $!";
print OUT ">$fname\n$str\n";
close(OUT);
}
__DATA__
aaccaataggagagatacatagcgaaccaataggagagatacatagcgaaccaataggagagatacatagcg
----------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 14 Sep 2001 21:58:46 GMT
From: "Patrik Birgersson" <nobody@no_where.net>
Subject: Re: parsing large DNA files into smaller files
Message-Id: <q4vo7.3791$sn6.480896@newsc.telia.net>
I'm not sure if this is the nicest way of doing this, but it works...
#!/usr/bin/perl -w
#
# Usage: dna.pl [filename]
use strict;
my
($orig,$start,$end,$len,$string,$total,$humanS,$humanE,$filename,$diff,$file
s);
open (BIGFILE, "$ARGV[0]");
$orig = <BIGFILE>;
close BIGFILE;
$total = length($orig);
$start = 0;
$end = 9999;
$diff = $total - $start;
$files = 0;
until ($diff == 0) {
$string = substr($orig,$start,$end);
$humanS = $start + 1;
$humanE = $end + 1;
$filename = "$humanS\_$humanE\.seq";
open (OUT, ">>$filename");
print OUT "\>$filename\n";
print OUT $string;
close OUT;
$start = $end + 1;
$end = $start + 9999;
if ($end > $total) {
$end = $total - $start;
}
$diff = $total - $start;
$files++;
}
print "Done! $ARGV[0] was devided into $files files.\n";
------------------------------
Date: Fri, 14 Sep 2001 19:21:28 GMT
From: kenlaird@yahoo.com (Ken Laird)
Subject: Re: Parsing problem (Please HELP )
Message-Id: <YMso7.10848$0a1.442880@amsnews02.chello.com>
In article <9nqjnm$gt5$1@mamenchi.zrz.TU-Berlin.DE>,
anno4000@lublin.zrz.tu-berlin.de says...
>
>According to Benjamin Goldberg <goldbb2@earthlink.net>:
>
>[in reply to Laird]
>
>> After taking a second look at what you wanted, I think I see my mistake.
>>
>> my @names;
>> while( <DATA> ) {
>> if( /^#/ ) {
>> push @names, /\b(name-\S+)/g;
>> } else if( my ($service) = /^\S+\s+(\S+)/ ) {
> ^^^^^^^
> elsif
>
>> print "name = ", unshift(@names), "\n";
> ^^^^^^^
> shift
>
>> print "service = $service\n";
>> }
>> }
>
>Please, it you post untested code, at least clearly mark it as such.
>
>Anno
Thank you very much.
Evrything works fine with the shift option.
Cordially
Ken
------------------------------
Date: Fri, 14 Sep 2001 14:39:19 -0500
From: "Bill Thomas" <acoustic_bill@yahoo.com>
Subject: Re: Passing a parameter from a text file???? Big Thanks!
Message-Id: <tq4n77p5phopc1@corp.supernews.com>
Just what I wanted to do. Works great! Thanks!
"Robert Sherman" <rsherman@ce.gatech.edu> wrote in message
news:3B9F5330.3ED01E25@ce.gatech.edu...
> Bill Thomas wrote:
> >
> > Any help will be greatly appreciated even if it is just reference to
some
> > good documentation or examples.
> >
> > I am pretty new to Perl and could use a little help.
> > I need to execute a program several times and pass different parameters
to
> > it each time.
>
> assuming you are using perl to write a wrapper for a compiled program
> (your post wasn't too clear on what 'foo' is):
>
> make a text file arguments.txt with one argument per line
>
> --------------------------------------
> open FILE, "arguments.txt";
> while (<FILE>){
> chomp;
> $result = `foo bar $_`;
> #maybe do something with $result here
> }
> --------------------------------------
>
> --
> robert sherman
> css, cee
> georgia institute of technology
> atlanta, ga, usa
------------------------------
Date: 14 Sep 2001 14:17:45 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Perl (slurping) is TOO much fun
Message-Id: <9ntl4p$4l2$1@charity.cs.utexas.edu>
In article <slrn9q39rb.og2.damian@puma.qimr.edu.au>,
Damian James <damian@qimr.edu.au> wrote:
>I say slurp when you can -- which is
>whenever you are sure the file won't become too big (for values of 'too
>big' that are appropriate to your system, taking into account the overheads
>of the OS, Perl and how many users there will be at any one time). Even then,
>for some operations it will be easier to slurp for now, then later tie() your
>data structure to a disk file.
Is there an easy tie() equivalent for this?
@foo = <FOO>;
# munge @foo to your satisfaction
seek FOO, 0, 0;
print FOO @foo;
What about this?
{
local $/ = undef;
$foo = <FOO>;
}
# munge $foo to your satisfaction
seek FOO, 0, 0;
print FOO $foo;
If so, that could be a good answer to some of the "how do you modify a
file in place" questions.
- Logan
--
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)
------------------------------
Date: Fri, 14 Sep 2001 21:17:00 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Perl (slurping) is TOO much fun
Message-Id: <x7vgilealc.fsf@home.sysarch.com>
>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:
BL> Uri Guttman wrote:
>> that is true but how often do you mung massive files? even slurping in
>> tens of megabytes is simple on most machines these days.
BL> You're acting very selfishly. If there's a chance that there will
BL> be tens of copies of these scripts runnign at the same time,
BL> you'll soon be running out of memory.
i never said to slurp all the time. it just is a tool that is useful and
not understood well by newbies. note that the buffers used are typically
reclaimed very soon after use so that memory is not wasted. and in many
cases, the text read in is much smaller than the corresponding data
structures built from them.
i am just saying it is a tool and you should choose it according to your
needs. if you slurp in large files, you pay for it. if you slurp in many
small files, it may be faster and allow for simpler code with no extra
cost in memory as it will be reused.
saying slurping is always bad is not productive. educate people on how
to do it and its costs and benefits.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: 14 Sep 2001 21:50:05 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Perl (slurping) is TOO much fun
Message-Id: <slrn9q4uoh.8l5.damian@puma.qimr.edu.au>
Tad McClellan chose Fri, 14 Sep 2001 15:18:03 GMT to say this:
>Damian James <damian@qimr.edu.au> wrote:
>>...
>>So it depends on how mauch RAM you have, and and how big the file is.
>
>And how many copies of this perl process might be running at the same time.
>And how often the program will be run.
Indeed, I had meant to allude to this in some way or other.
>And perhaps how much swap space you have.
Hopefully one would move to a line-by-line approach before that became an
issue.
>My default approach is to do it line-by-line.
As is mine, even in many cases where slurping is easier. I guess I'm not
being very consistent there :-). I complain about the ridiculous RAM
requirements of a lot of today's software often enough, c'est la vie.
>>...
>>whenever you are sure the file won't become too big (for values of 'too
>>big' that are appropriate to your system, taking into account the overheads
>>of the OS, Perl and how many users there will be at any one time).
>
>And for appropriate values of the "sure" in "whenever you are sure".
Indeed - ones that include due regard to the future use of the system in
question.
>>Remember that these days RAM is cheap and you need a lot of data to use it
>>up. And reading from RAM is much faster than reading from disk.
>
>I don't usually slurp to get "faster". I slurp to get "easier to write"
>or "easier to maintain" though (labor is my default "thing to optimize").
Likewise, and this was really an afterthought -- people seem to be
attracted to micro-optimisations like that. [aside: Oh Lord, let me optimise
better for labour -- spent two hours yesterday tracking an extremely subtle
bug that turned out to be caused by bad laziness, reusing a subsystem for an
other-than-planned purpose without generalising it sufficently].
I guess I hadn't meant to sound so strident in advocating slurping, I had
meant to point out that one doesn't need to avoid it for the sake of
avoiding it. That would be merely an aesthetic practice. Of course robust
programming that takes into account a wide variety of scenarios will
attempt to use as little RAM as possible.
Cheers,
Damian
--
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker, ### rev 3.3 -- stupidectomy performed :-)
------------------------------
Date: Fri, 14 Sep 2001 16:08:08 -0400
From: Krister Bruhwel <bruhwel@jlab.org>
Subject: perl command line flags
Message-Id: <Pine.LNX.4.33.0109141551110.5106-100000@hallbele>
Hello,
I'm new to this list and perl.
I would like to know if there are any resources on the perl command line
flags. For example:
a) command line substitution:
perl -p -i -e 's/this/that/g' filename
b)) print an item from the standard output of a program:
someProgram | perl -nale 'print $F[3]'A
If i try perl -pie in the first example it doesn't like it. The order of
the flags seem to matter. I'm looking for consistency, or a method that I
can follow. I would like to use perl instead of sed and awk, but i need a
consitantcy that will make it easy for me to remember.
Most will probably say "put it in a script", but I like to be able to do
some things on the command line. Makes my life easier. Anyone who loves shell
command line shortcuts will appreciate the ease of doing some things on
the fly. I like to put stuff in files too, but for a simple substitution, ect
its nice. That's what I like about sed and awk. For example:
setenv myIPvariable `host myDNS |awk '{print $NF}'`
This is handy and simple. Keeps my hands of the mouse for the old middle
click paste deal. I now know how to do it in perl (example b from
above). Perl is better than sed and awk as I understand, and I would like
to use it. But there isn't much on the web about command line execution
of shell scripts thus far.
Thanks for any input,
Krister
------------------------------
Date: Fri, 14 Sep 2001 22:23:22 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: perl command line flags
Message-Id: <pmp4qtcvel3o0jc1thgtepk4sd4c6bli2v@4ax.com>
On Fri, 14 Sep 2001, Krister Bruhwel <bruhwel@jlab.org> wrote:
>I'm new to this list and perl.
Read the FAQ first, ask later.
>I would like to know if there are any resources on the perl command line
>flags. For example:
Try "perldoc perlrun". It's all there at your finger tips :-)
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 14 Sep 2001 15:49:25 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: perl command line flags
Message-Id: <3BA26D55.EE8C170D@home.com>
Krister Bruhwel wrote:
>
> I'm new to this list and perl.
> I would like to know if there are any resources on the perl command
> line flags.
Yes, the perlrun manpage. Type 'perldoc perlrun'
> For example:
>
> a) command line substitution:
> perl -p -i -e 's/this/that/g' filename
> [...]
>
> If i try perl -pie in the first example it doesn't like it. The
> order of the flags seem to matter.
It's not the order, it's that the -i flag expects an optional value to
use to create a backup copy for in-place edits. Saying -pie tells perl
to use 'e' as the extension for the backup and eats up your -e flag.
> Most will probably say "put it in a script", but I like to be able
> to do some things on the command line.
For simple stuff like this? Naw. No point in making a script out of it
unless you're going to use it again.
> But there isn't much on the web about command line execution
> of shell scripts thus far.
No need to look to the web. Perl comes with a massive amount of
documentation and (on most platforms) a utility for searching and
reading it called perldoc.
Run these from your command prompt to get started:
perldoc perldoc
perldoc perl
-mjc
------------------------------
Date: Fri, 14 Sep 2001 21:37:46 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl command line flags
Message-Id: <slrn9q4rbu.kpp.tadmc@tadmc26.august.net>
Krister Bruhwel <bruhwel@jlab.org> wrote:
>I'm new to this list and perl.
This is not a mailing list.
This is a Usenet newsgroup.
Not at all the same thing.
There are some guidelines for posting at:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
>I would like to know if there are any resources on the perl command line
>flags.
perldoc perlrun
>For example:
>
>a) command line substitution:
> perl -p -i -e 's/this/that/g' filename
>b)) print an item from the standard output of a program:
> someProgram | perl -nale 'print $F[3]'A
>
>If i try perl -pie in the first example it doesn't like it.
Then don't do that. :-)
>The order of
>the flags seem to matter.
I have never heard command line switches called "flags" before,
that is going to confuse people.
The order of switches might matter. Depends on what switches and
whether they take arguments or not.
>I'm looking for consistency, or a method that I
>can follow.
Never gang multiple switches together, always use individual ones.
Simple. Easy to remember. Consistent. Problem solved!
>Perl is better than sed and awk
That seems a safe statement, since it is a superset of sed/awk.
In fact, you can convert sed/awk programs to perl programs
automatically using the 's2p' and 'a2p' utilities installed
along with perl itself. (see if you have them on your system)
>But there isn't much on the web about command line execution
^^^^^^^^^^
That is a very poor resource compared to the documentation that
actually shipped with the same software you are using.
Use the docs Luke.
>of shell scripts thus far.
Huh? This is the first mention of shell scripts in your post.
I see perl scripts. I see awk scripts. I see no shell scripts...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 14 Sep 2001 13:30:16 -0700
From: "terminalsplash" <shino_korah@yahoo.com>
Subject: Perl to MS SQL
Message-Id: <9ntpcl$7eq@news.or.intel.com>
hi
I want to upload data to Microsoft SQL in a windows machine using a Perl
script in Linux machine.
Is it possible? If yes what is the best way to do it?
------------------------------
Date: Fri, 14 Sep 2001 22:51:27 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: Perl to MS SQL
Message-Id: <adr4qt880uo6359dqgj3do5qku7i621je8@4ax.com>
On Fri, 14 Sep 2001, "terminalsplash" <shino_korah@yahoo.com> wrote:
> I want to upload data to Microsoft SQL in a windows machine using a Perl
>script in Linux machine.
Try "perldoc -q database" and follow the pointers given.
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 14 Sep 2001 19:31:07 GMT
From: Alex BATKO <abatko@cs.mcgill.ca>
Subject: pipe to passwd
Message-Id: <Pine.GSO.4.10.10109141520540.18608-100000@skinner.cs.mcgill.ca>
Hello.
I'd like to open a pipe to the program ``passwd'' inorder to change
a password. When I do this, it prompts me despite my printing two
lines to it (initial/confirmation) as in the example below.
(I've tried using \n, ^D, \r, and \r\n, and I get the same results).
Can anyone help me with this ?
my $PASSWD = '/usr/bin/passwd';
open( PASSWD, "| $PASSWD -r nis $login" );
print PASSWD "123abcDE\n";
print PASSWD "123abcDE\n";
close( PASSWD );
------------------------------
Date: Fri, 14 Sep 2001 21:35:31 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: pipe to passwd
Message-Id: <rtm4qt44k0b4go17e0870du24okmu25fp2@4ax.com>
On Fri, 14 Sep 2001, Alex BATKO <abatko@cs.mcgill.ca> wrote:
>I'd like to open a pipe to the program ``passwd'' inorder to change
>a password. When I do this, it prompts me despite my printing two
>lines to it (initial/confirmation) as in the example below.
>(I've tried using \n, ^D, \r, and \r\n, and I get the same results).
>
>Can anyone help me with this ?
See the answers to your initial question in another thread. No, don't
just see them, try to read and understand them :-P
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 14 Sep 2001 19:38:20 GMT
From: Alex BATKO <abatko@cs.mcgill.ca>
Subject: Re: pipe to passwd
Message-Id: <Pine.GSO.4.10.10109141535090.23409-100000@skinner.cs.mcgill.ca>
I should have shown an example of the programming running:
# perl -w pw.pl
New password:
On Fri, 14 Sep 2001, Alex BATKO wrote:
> I'd like to open a pipe to the program ``passwd'' inorder to change
> a password. When I do this, it prompts me despite my printing two
> lines to it (initial/confirmation) as in the example below.
> (I've tried using \n, ^D, \r, and \r\n, and I get the same results).
>
> Can anyone help me with this ?
>
>
> my $PASSWD = '/usr/bin/passwd';
>
> open( PASSWD, "| $PASSWD -r nis $login" );
>
> print PASSWD "123abcDE\n";
> print PASSWD "123abcDE\n";
>
> close( PASSWD );
------------------------------
Date: 14 Sep 2001 15:08:25 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: pipe to passwd
Message-Id: <9nto3p$5au$1@charity.cs.utexas.edu>
In article <Pine.GSO.4.10.10109141520540.18608-100000@skinner.cs.mcgill.ca>,
Alex BATKO <abatko@cs.mcgill.ca> wrote:
>I'd like to open a pipe to the program ``passwd'' inorder to change
>a password. When I do this, it prompts me despite my printing two
>lines to it (initial/confirmation) as in the example below.
>(I've tried using \n, ^D, \r, and \r\n, and I get the same results).
Your desire to open a pipe to "passwd" is probably based on a belief
that passwd reads its standard input. It doesn't. Instead, it opens
its tty reads that.
A rough Perl equivalent of what "passwd" does would be this:
#! /usr/local/bin/perl
open (TTY, "+</dev/tty") or die;
select TTY;
$| = 1;
print TTY "New password:";
$new1 = <TTY>;
print TTY "\nRe-enter new password:";
$new2 = <TTY>;
print TTY "\n";
Actually, it also turns "echo" off on the tty, but that's a detail.
What you need to do if you want to do this is to create a
pseudo-tty for "passwd" to interact with. If you want to
do this in Perl, you can use the Expect module. See
http://search.cpan.org/search?mode=module&query=expect .
Hope that helps.
- Logan
--
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)
------------------------------
Date: 14 Sep 2001 11:56:14 -0700
From: rothman@pobox.com (Geoff Rothman)
Subject: report duplicate ip addresses in file
Message-Id: <a4f5b2c8.0109141056.3b15a023@posting.google.com>
I want to report duplicate IPs to the console. This script removes
duplicate IPs and puts the results into the @uniq array...I want to do
the opposite but can't figure out how.
thanks!
geoff
$path = "d:\\temp\\ips.txt";
open(FILE,"$path") || die "can't open $path";
@list = <FILE>; # Read it into an array
close(FILE); # Close the file
#print @list; # Print the array
%seen = ();
@uniq = ();
foreach $item (@list) {
push(@uniq, $item) unless $seen{$item}++;
}
------------------------------
Date: 14 Sep 2001 19:27:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: report duplicate ip addresses in file
Message-Id: <9ntlnn$83j$1@mamenchi.zrz.TU-Berlin.DE>
According to Geoff Rothman <rothman@pobox.com>:
> I want to report duplicate IPs to the console. This script removes
> duplicate IPs and puts the results into the @uniq array...I want to do
> the opposite but can't figure out how.
All you have to do is rename "@uniq" to "@dupes" and invert the
condition of the "push" instruction:
> thanks!
> geoff
>
> $path = "d:\\temp\\ips.txt";
Obviously you're not running under strict. Use lexical variables
unless there's a reason, so it should be "my $oath = ...". The
same goes for the other variables below.
> open(FILE,"$path") || die "can't open $path";
The error message should contain $!, so you know what went bang.
> @list = <FILE>; # Read it into an array
> close(FILE); # Close the file
A case of mindless file slurping. Nothing is gained by reading a
file into a list when all you do is a single pass over the list.
> #print @list; # Print the array
>
> %seen = ();
> @uniq = ();
my @dupes;
> foreach $item (@list) {
while ( my $item = <FILE> ) {
> push(@uniq, $item) unless $seen{$item}++;
push @dupes, $item if $seen{ $item}++;
> }
This puts multiple duplicates on @dupes if there is more than one.
If you want each one mentioned only once, use
push @dupes, $item if $seen{ $item}++ == 1;
Anno
------------------------------
Date: Fri, 14 Sep 2001 21:30:07 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: report duplicate ip addresses in file
Message-Id: <9sl4qtk6uqckq7ko0ja6ieid1hi0ia2tmr@4ax.com>
On 14 Sep 2001, rothman@pobox.com (Geoff Rothman) wrote:
>I want to report duplicate IPs to the console. This script removes
>duplicate IPs and puts the results into the @uniq array...I want to do
>the opposite but can't figure out how.
>@list = <FILE>; # Read it into an array
This is potentially bad - the file could be huge, and you need to
iterate over the lines anyways - so why not do it line by line?
while( defined( my $ip = <FILE> ) ){
print "dup: $ip" if ++$seen{$ip} == 2;
}
If you need a list later, you could do it this way:
#!/usr/bin/perl -w
use strict;
my %seen;
while( defined( my $ip = <DATA> ) ){
$seen{$ip}++;
}
print "Duplicate IP adresses:\n";
# note: keys contain a trailing \n!
print grep { $seen{$_} > 1 } keys %seen
__DATA__
127.0.0.1
1.21.3.4
2.1.3.5
6.32.45.1
127.0.0.1
23.54.2.1
127.0.0.1
12.45.1.45
127.0.0.1
2.1.3.5
__END__
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 14 Sep 2001 19:30:10 GMT
From: "Patrik Birgersson" <nobody@no_where.net>
Subject: Urgently need help with Net::SSH::Perl / Math::Pari / @INC and loadable objects
Message-Id: <6Vso7.55720$e5.2859217@newsb.telia.net>
Hi there!
Sorry for the cross-post, but I really need help as fast as possible.
Rows will probably wrap.
I am trying to use the Net::SSH::Perl module with Perl 5.6.1 on a
i686 RH 6.2 Linux box.
My code is quite basic so far (mostly from Net::SSH:Perl manpage
since I want to start to be able to establish a connection before I
develop any further):
#!/usr/bin/perl -w
use Net::SSH::Perl;
use strict;
my
($ssh,$host,$user,$pass,$stdout,$stderr,$exit,$cmd,$port,$back,$prot);
$host = "$ARGV[0]";
$port = "$ARGV[1]";
$user = "$ARGV[2]";
$pass = "$ARGV[3]";
$ssh = Net::SSH::Perl->new("$host", port=>($port), debug=>'true',
protocol=>'2,1', interactive=>'true');
$ssh->login($user, $pass);
$back = $ssh->incoming_data;
print "\n\nIncoming: $back\n\n";
($stdout, $stderr, $exit) = $ssh->cmd($cmd);
This code seems to work so far that a connection is made...
box: Reading configuration data /home/my_username/.ssh/config
box: Reading configuration data /etc/ssh_config
box: Allocated local port 1023.
box: Connecting to box, port 22.
box: Remote protocol version 1.99, remote software version 2.3.0 SSH
Secure Shell (non-commercial)
However, I'm only allowing SSH2 on my SSH server and this is where my
problem begins.
If I'm using protocol=>'1' I don't get any errors from Perl, but my
connection is closed (as should be).
When I'm trying to use SSH2 I get the following error:
Can't locate loadable object for module Math::Pari in @INC (@INC
contains:
/usr/local/ActivePerl-5.6/lib/5.6.1/i686-linux-thread-multi
/usr/local/ActivePerl-5.6/lib/5.6.1
/usr/local/ActivePerl-5.6/lib/site_perl/5.6.1/i686-linux-thread-multi
/usr/local/ActivePerl-5.6/lib/site_perl/5.6.1
/usr/local/ActivePerl-5.6/lib/site_perl .)
at
/usr/local/ActivePerl-5.6/lib/site_perl/5.6.1/Net/SSH/Perl/Util/SSH2MP
.pm line 6
I do have Math::Pari installed
bash# locate Pari.pm
/usr/local/ActivePerl-5.6/lib/5.6.1/Math/Pari.pm
However, I looked into Pari.pm and saw this on row 653 & 654:
require Exporter;
require DynaLoader;
So I checked for those:
bash# locate Exporter DynaLoader
/usr/local/ActivePerl-5.6/html/lib/Exporter
/usr/local/ActivePerl-5.6/html/lib/Exporter/Heavy.html
/usr/local/ActivePerl-5.6/html/lib/Exporter.html
/usr/local/ActivePerl-5.6/lib/5.6.1/Exporter
/usr/local/ActivePerl-5.6/lib/5.6.1/Exporter/Heavy.pm
/usr/local/ActivePerl-5.6/lib/5.6.1/Exporter.pm
/usr/man/man3/Exporter.3
/usr/man/man3/Exporter::Heavy.3
/usr/local/ActivePerl-5.6/html/lib/DynaLoader.html
/usr/local/ActivePerl-5.6/lib/5.6.1/i686-linux-thread-multi/DynaLoader
.pm
/usr/local/ActivePerl-5.6/lib/5.6.1/i686-linux-thread-multi/auto/DynaL
oader
/usr/local/ActivePerl-5.6/lib/5.6.1/i686-linux-thread-multi/auto/DynaL
oader/DynaLoader.a
/usr/local/ActivePerl-5.6/lib/5.6.1/i686-linux-thread-multi/auto/DynaL
oader/autosplit.ix
/usr/local/ActivePerl-5.6/lib/5.6.1/i686-linux-thread-multi/auto/DynaL
oader/dl_expandspec.al
/usr/local/ActivePerl-5.6/lib/5.6.1/i686-linux-thread-multi/auto/DynaL
oader/dl_find_symbol_anywhere.al
/usr/local/ActivePerl-5.6/lib/5.6.1/i686-linux-thread-multi/auto/DynaL
oader/dl_findfile.al
/usr/local/ActivePerl-5.6/lib/5.6.1/i686-linux-thread-multi/auto/DynaL
oader/extralibs.ld
/usr/man/man3/DynaLoader.3
Could any of you plz help me out... I really need to get this
working... ;-)
Thnx!!
Patrik Birgersson
------------------------------
Date: 14 Sep 2001 20:03:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Urgently need help with Net::SSH::Perl / Math::Pari / @INC and loadable objects
Message-Id: <9ntnpo$9kr$2@mamenchi.zrz.TU-Berlin.DE>
According to Patrik Birgersson <nobody@no_where.net>:
> Hi there!
>
> Sorry for the cross-post, but I really need help as fast as possible.
> Rows will probably wrap.
So long.
Anno
------------------------------
Date: 14 Sep 2001 18:16:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: use autouse 'Data::Dumper' => qw(Dump);
Message-Id: <9nthhb$5bl$1@mamenchi.zrz.TU-Berlin.DE>
According to Alexander Farber (EED) <eedalf@eed.ericsson.se>:
> Hi guys,
>
> I'd like to only load the Data::Dumper module in my CGI-script
> if the DEBUG information is requested (by a string in PATH_INFO):
>
> $DEBUG = $query -> path_info =~ /DEBUG/;
>
> So I've tried doing it this way:
>
> use autouse 'Data::Dumper' => qw(Dump);
^^^^
Here is your error. You want "Dumper" instead of "Dump".
> ...
> print '<PRE>',
> Dump ([$hohref, $cnaref], [qw(hohref cnaref)]),
Again, the name of the routine is "Dumper". Carefully (re-)reading
the documentation of Data::Dumper might have turned that up. Also,
when I try your code, an error happens at this point. Didn't you
see one?
[snip]
Anno
------------------------------
Date: Fri, 14 Sep 2001 21:31:48 GMT
From: "OverlordQ" <overlord_q@hotmail.com>
Subject: Using Perl to post regular usenet messages.
Message-Id: <8Huo7.293013$GN.41352272@typhoon.kc.rr.com>
Any Idea on where to get started? any docs out-there which help?
Any clues on which module would be required?
TIA.
--
-------------------------------
Newsgroup: alt.eo
For all your Evil Overlord Needs
http://www.thedarkcitadel.com
------------------------------
Date: Fri, 14 Sep 2001 23:52:19 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: Using Perl to post regular usenet messages.
Message-Id: <mbu4qtcn4h8kdn543850iv97kq0k5nl5ri@4ax.com>
On Fri, 14 Sep 2001, "OverlordQ" <overlord_q@hotmail.com> wrote:
>Any Idea on where to get started? any docs out-there which help?
>
>Any clues on which module would be required?
- http://search.cpan.org/search?mode=module&query=NNTP
- perldoc Net::NNTP
- http://www.ietf.org/rfc/rfc977.txt
- http://www.ietf.org/rfc/rfc1036.txt
And the supreme being help you if you want to send spam :-P
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 14 Sep 2001 21:55:57 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Using Perl to post regular usenet messages.
Message-Id: <slrn9q4sgv.kth.tadmc@tadmc26.august.net>
OverlordQ <overlord_q@hotmail.com> wrote:
>Any Idea on where to get started? any docs out-there which help?
>
>Any clues on which module would be required?
Here is the program that I use for autoposting the Posting Guidelines
that can also be seen at:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
------------------------------
#!/usr/bin/perl -w
use strict;
use News::NNTPClient;
my $server = 'gnews.august.net';
my $group = 'comp.lang.perl.misc';
my $file = '/home/tadmc/perl/guide_clpmisc/clpmisc_guidelines.text';
my $email = 'tadmc@augustmail.com';
### read entire body and extract Subject
open(GUIDE, $file) or die "could not open '$file' $!";
my @body = <GUIDE>;
chomp @body;
close(GUIDE);
my $subject = (grep /^Posting Guidelines/, @body)[0];
### set the headers
my @headers = (
"Newsgroups: $group",
"Subject: $subject",
"From: $email",
);
### post the article
my $client = new News::NNTPClient($server);
die "could not connect to '$server'" unless defined $client;
die "problem posting\n" unless $client->post(@headers, '', @body);
print "article successfully posted\n";
exit 0; # succeeded
------------------------------
Use this power only for good, else hair will grow on your
palms or something...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 1749
***************************************