[22641] in Perl-Users-Digest
Perl-Users Digest, Issue: 4862 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 18 14:12:07 2003
Date: Fri, 18 Apr 2003 11:10:10 -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, 18 Apr 2003 Volume: 10 Number: 4862
Today's topics:
Problem with File::Temp and FTP transfer <cpryce@pryce.net>
Re: Problem with File::Temp and FTP transfer <cpryce@pryce.net>
Q. Basic Perl Tutorial ? (for a not-so-bright newbie) (Jim)
Re: remembering values <noreply@gunnar.cc>
Re: remembering values <tore@aursand.no>
Re: remembering values <spam@thecouch.homeip.net>
Re: remembering values <chris_12003@yahoo.com>
Still Stumped <delautenschl@[nospam]wisc.edu>
Re: syntax error with XML::Simple <nutate@speakeasy.net>
unix system komand <uruz@inode.at>
Re: unix system komand (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 18 Apr 2003 10:55:46 -0500
From: cp <cpryce@pryce.net>
Subject: Problem with File::Temp and FTP transfer
Message-Id: <BAC58A32.1B725%cpryce@pryce.net>
I'm creating simple text files with an HTML interface, and uploading these
text files to a directory on a Unix file system.
I've got the following two sub routines (printError() is a generic sub for
outputting error messages to the browser). USER has the proper permissions
to create files in REMOTE_DIR, and using the same username and pass, the
temp file can put with ftp from the command line. The data is written to the
tempfile (see log and cat entries below).
REMOTE_FILE is generated in the proper directory, but it is blank (zero k).
Any ideas?
sub catalog_dir {
my ($path, $current, $base ) = @_;
# Check data integrity. check_data returns an arrayref of missing
# fields. If it is undef, all the correct data is here.
my $err = check_data();
$err && printError( $err );
my %args = ( FTP_HOST => 'xxxxxx',
REMOTE_DIR => $path,
USER => 'cpryce',
PASS => 'xxxxxxx',
DEBUG => '1',
REMOTE_FILE => 'catalog.txt'
);
my ($fh, $filename) = tempfile();
printError("Failed to create tempfile") unless $fh;
my @fields = qw(project title discipline service keywords);
my %info = map { $_ => param( $_ ) } @fields;
foreach ( @fields ){
print $fh "$_:$info{$_}\n";
}
if ( upload_file( $filename, %args ) ) {
# I've first tried feeding it $fh, but that didn't work either
print redirect(-url=>$redirect);
}
else {
printError( "File Upload Failed" );
}
}
sub upload_file {
# require Net::FTP;
use Net::FTP;
my ($fh, %args) = @_;
my $ftp;
# call the class constructor
if ( $ftp = Net::FTP->new($args{FTP_HOST}, Timeout=>30, Debug=>0 ) ) {
print STDERR "Connected" if $args{DEBUG};
}
else {
print STDERR "No FTP Connection." If $args{DEBUG};
return undef;
}
# login
if ($ftp->login( $args{USER}, $args{PASS} )) {
# if the login succedes, change into the right directory
$ftp->cwd( $args{REMOTE_DIR} ) or return undef;
# put the file
$ftp->put( $fh, $args{REMOTE_FILE} ) or return undef;
$ftp->quit or return undef;
my $time = localtime();
print STDERR "Upload of $fh to $args{FTP_HOST} succeeded at $time\n"
if $args{DEBUG};
} else {
print STDERR "Login failed for $args{FTP_HOST}\n" if $args{DEBUG};
return undef;
}
return 1;
}
# tail -f error_log
Negotiated connection with xxxxxxx
Upload of /tmp/YxKQKeK1BF to xxxxxxx succeeded at Fri Apr 18 10:41:09 2003
# cat /tmp/YxKQKeK1BF
project:1234
title:Alexandria Bypass Study
discipline:ENVS
service:PM
keywords:alexandria, alignment, alternative, assessment, congestion, county,
cultural, douglas, eaw, impact, noise, quality, resourc
es, safety, study, visual, water, wetland
------------------------------
Date: Fri, 18 Apr 2003 12:02:14 -0500
From: cp <cpryce@pryce.net>
Subject: Re: Problem with File::Temp and FTP transfer
Message-Id: <BAC599C6.1B745%cpryce@pryce.net>
in article BAC58A32.1B725%cpryce@pryce.net, cp at cpryce@pryce.net wrote on
4/18/03 10:55 AM:
> I'm creating simple text files with an HTML interface, and uploading these
> text files to a directory on a Unix file system.
>
> I've got the following two sub routines (printError() is a generic sub for
> outputting error messages to the browser). USER has the proper permissions
> to create files in REMOTE_DIR, and using the same username and pass, the
> temp file can put with ftp from the command line. The data is written to the
> tempfile (see log and cat entries below).
>
> REMOTE_FILE is generated in the proper directory, but it is blank (zero k).
> Any ideas?
>
Answered my own question, I forgot to close the filehandle first.
------------------------------
Date: Fri, 18 Apr 2003 14:06:04 GMT
From: harley.davidsno@mailcity.com (Jim)
Subject: Q. Basic Perl Tutorial ? (for a not-so-bright newbie)
Message-Id: <3ea00459.412284@nntp.ix.netcom.com>
Hi.
I want to get into Perl. It seems no matter what book I pick up these
days, on whatever subject, that it is written for people who already
know the subject.
What I want to do is is use Perl to make my own:
Page counters and Message boards (with the reply option).
Or at least to copy them, and place them where they need to be and
then to link to properly link to them, from my own web pages.
Can you recommend a study source which gives me the not only the basic
Perl commands/usage, but also does an excellent job illustrating the
big picture?
I have the Internet web host I've always used, which doesn't allow
Perl or CGI. BUt I understand there are sites out there which I can
sign up with, which do allow it.
One question for now: If I want to use my own written Perl script,
can I have it on a separate site and simply link to it, or does the
CGI-BIN, and so on need to be on the same server as my own pages ?
Thanks,
Jim
------------------------------
Date: Fri, 18 Apr 2003 12:21:50 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: remembering values
Message-Id: <b7ok9q$31mgb$1@ID-184292.news.dfncis.de>
Chris wrote:
> How do I call a cgi so that each time I call it, it remembers the
> previous variable values? I've thought about appending the
> variables, something like mycgi.cgi?var1=a?var2=b but am not sure
> how to do this.
Your question seems a little odd to me. You'd better explain what it
is you want the script to do, in order to bring some light on why you
are asking that question, and in order to give us a chance to possibly
suggest a better approach.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 18 Apr 2003 14:20:41 +0200
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: remembering values
Message-Id: <pan.2003.04.18.12.03.00.975287@aursand.no>
On Thu, 17 Apr 2003 22:49:48 -0700, Chris wrote:
> How do I call a cgi so that each time I call it, it remembers the
> previous variable values?
Appending them to your query isn't very nice. I would go for a
session-based solution.
If you're already using CGI.pm (which you should), you could take a look
at CGIS (which is CGI.pm with session support).
If that's not good enough for you, a search for 'session' at CPAN would do
the trick.
--
Tore Aursand <tore@aursand.no>
"You know the world is going crazy when the best rapper is white, the best
golfer is black, France is accusing US of arrogance and Germany doesn't
want to go to war."
------------------------------
Date: Fri, 18 Apr 2003 09:30:54 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: remembering values
Message-Id: <m6Tna.11872$em4.248056@weber.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Chris wrote:
> How do I call a cgi so that each time I call it, it remembers the previous
> variable values? I've thought about appending the variables, something like
> mycgi.cgi?var1=a?var2=b but am not sure how to do this.
Due to the fact that CGI invocations are stateless, you need to somehow
store the variables *somewhere* for the next time the CGI is executed.
Common places to store them are:
1. In hidden <input> fields in the last html code sent to the client
2. In a cookie sent to the client
3. In a server-side file/database/etc + a client cookie that identifies
the session id
#1 and #2 can be accomplished by a simple print statement, and the
values can be retrieved via the CGI module
#3 is a bit tricky but is my preferred method. I use the CGI::Session
module which does a good job at providing an easy OO interface to
sessions and persistant veriables, and again a print() and use CGI for
sending and retrieving the session ID via client-side cookies.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+n/4SeS99pGMif6wRAp39AJ9i7Y6Po3AyKq7KUOu8bHEzTtvnlQCgxIV4
ok4EaTaHeFnA6UfsN3BBw54=
=4tNP
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 18 Apr 2003 09:19:59 -0700
From: "Chris" <chris_12003@yahoo.com>
Subject: Re: remembering values
Message-Id: <va09e9g4bflj4b@corp.supernews.com>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:b7ok9q$31mgb$1@ID-184292.news.dfncis.de...
> Your question seems a little odd to me. You'd better explain what it
> is you want the script to do, in order to bring some light on why you
> are asking that question, and in order to give us a chance to possibly
> suggest a better approach.
I have a cgi script that displays a webpage asking the user to click option
1 or option 2. The cgi script is called again with an argument
myscript.cgi?option=2. The cgi script see's they've already answered
question 1 so it displays question 2. The results need to either be
appended or saved using another method. I've thought about saving the
variable in a hidden field but since I'm not using forms this isn't
possible. Cookies may work but I'm reading they have a size limit. Session
variables seems to be the way to go.
Now if I can just find a sample script that uses Session variables? Any
idea where I can find an sample script for session variables, I've found the
docs for session variables at cpan.org
Thanks,
Chris
------------------------------
Date: Fri, 18 Apr 2003 10:25:02 -0500
From: pooba53 <delautenschl@[nospam]wisc.edu>
Subject: Still Stumped
Message-Id: <b7p5cd$53a$1@news.doit.wisc.edu>
See the data below to see the data I'm working with. Each entry is a
gene "chunk" including the name of the gene, the starting point of the
sequence and the end point for this particular "record".
What I'm trying to do is create a hash that has the gene as the key and
the range of each entry as the values. Therefore I will have multiple
values per key.
The end product would be like this:
$hash = (
Gene=> [ [begin..end], [begin..end] ],
);
The "begin..end" represents the range of numbers for each entry below
associated with the appropriate gene name.
My goal is to capture only the unique numbers within each range
associated with each gene. From a prior post, I know the following works:
my %hash = (
CG2349 => [ [1,2,3,4,5], [2,3,4,5,6,7], [10,11,12,13] ],
);
while (my ($key,$aref) = each %hash) {
my %seen;
my @unique = grep !$seen{$_}++, map @$_, @$aref;
print "unique elements for $key : @unique\n";
}
The problem I'm having is getting my hash set up to look like the above.
I've tried the following within the loop that generates the output below:
@range = ($begin..$end);
push ( @{$AllGenes{$gene}}, @range);
I don't think this is forming my hash properly as the sample code above
does not work. If I manually create a hash, it does indeed output only
the unique numbers.
I really appreciate the help, folks.
-Dan
Gene: CG3038
Begin: 3118
End: 3280
Gene: CG3038
Begin: 2850
End: 3016
Gene: CG3038
Begin: 1488
End: 2784
Gene: CG3038
Begin: 2850
End: 3271
Gene: CG3038
Begin: 1488
End: 2784
Gene: CG2995
Begin: 3445
End: 5034
Gene: CG2995
Begin: 5820
End: 7676
Gene: CG2995
Begin: 7732
End: 7973
Gene: CG2995
Begin: 8064
End: 8431
Gene: CG2995
Begin: 8488
End: 8729
Gene: CG2995
Begin: 8789
End: 8979
Gene: CG2995
Begin: 9040
End: 9201
Gene: CG2995
Begin: 9261
End: 9798
Gene: CG2995
Begin: 9868
End: 10241
Gene: CG2995
Begin: 10507
End: 11463
Gene: CG4376
Begin: 1798819
End: 1799083
Gene: CG4376
Begin: 1791727
End: 1791973
Gene: CG4376
Begin: 1787215
End: 1787631
Gene: CG4376
Begin: 1786987
End: 1787140
Gene: CG4376
Begin: 1786613
End: 1786698
Gene: CG4376
Begin: 1784707
End: 1784799
Gene: CG4376
Begin: 1784293
End: 1784643
Gene: CG4376
Begin: 1784056
End: 1784234
Gene: CG4376
Begin: 1782547
End: 1783681
Gene: CG4376
Begin: 1781866
End: 1782471
Gene: CG4376
Begin: 1798819
End: 1799083
Gene: CG4376
Begin: 1791727
End: 1791973
Gene: CG4376
Begin: 1787215
End: 1787631
Gene: CG4376
Begin: 1786987
End: 1787140
Gene: CG4376
Begin: 1785437
End: 1785522
Gene: CG4376
Begin: 1784707
End: 1784799
Gene: CG4376
Begin: 1784293
End: 1784643
Gene: CG4376
Begin: 1784056
End: 1784234
Gene: CG4376
Begin: 1782547
End: 1783681
Gene: CG4376
Begin: 1781866
End: 1782471
Gene: CG4376
Begin: 1798819
End: 1799083
Gene: CG4376
Begin: 1791727
End: 1791973
Gene: CG4376
Begin: 1787215
End: 1787631
Gene: CG4376
Begin: 1786987
End: 1787140
Gene: CG4376
Begin: 1786547
End: 1786698
Gene: CG4376
Begin: 1784707
End: 1784799
Gene: CG4376
Begin: 1784293
End: 1784643
Gene: CG4376
Begin: 1784056
End: 1784234
Gene: CG4376
Begin: 1782547
End: 1783681
Gene: CG4376
Begin: 1781866
End: 1782471
------------------------------
Date: Fri, 18 Apr 2003 12:19:12 -0400
From: "Rich Seymour" <nutate@speakeasy.net>
Subject: Re: syntax error with XML::Simple
Message-Id: <pan.2003.04.18.16.19.10.396955@speakeasy.net>
On Thu, 17 Apr 2003 16:57:59 -0500, Tad McClellan wrote:
> Rich Seymour <nutate@speakeasy.net> wrote:
>
>> require 'XML::Simple'
> ^^
> ^^
>
> Where is the semicolon?
I just left it out when I was quickly formatting the code for the post,
in the end, I just commented out line 671. It threw up another error in
the 800's, I commented that line out and tada, it works. I'm still not
sure why exactly it was having trouble, but clearly the latest version has
some issues handling the syntax that the older version (the number of
which I wish I new) didn't have.
Thanks though,
Rich
------------------------------
Date: Fri, 18 Apr 2003 11:29:52 +0200
From: uruz <uruz@inode.at>
Subject: unix system komand
Message-Id: <3e9fc5a5$1@e-post.inode.at>
hi
i has coded a programm watching for users on a unix system
My problem is as a part of this programm i use the system command
`write root`
this works as next i print a string.
but how should i send the strg-d command to close the write process
code:
print "writing to:";
`write uruz`;
print "hi uruz\n";
???? strg-d
thx
URUZ
------------------------------
Date: Fri, 18 Apr 2003 08:17:33 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: unix system komand
Message-Id: <slrnb9vund.a43.tadmc@magna.augustmail.com>
uruz <uruz@inode.at> wrote:
> My problem is as a part of this programm i use the system command
> `write root`
> this works as next i print a string.
> but how should i send the strg-d command to close the write process
> code:
> print "writing to:";
> `write uruz`;
> print "hi uruz\n";
> ???? strg-d
If I understand your questions, then I think you should read
the "Pipe Opens" section in:
perldoc perlopentut
--
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 4862
***************************************