[24526] in Perl-Users-Digest
Perl-Users Digest, Issue: 6706 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 18 21:05:43 2004
Date: Fri, 18 Jun 2004 18: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, 18 Jun 2004 Volume: 10 Number: 6706
Today's topics:
Re: "antispam" perl mods? <postmaster@castleamber.com>
Re: $NF for perl <remorse@partners.org>
Re: Encoding question <kruger@math.fu-berlin.de>
float storage (ivo welch)
Re: float storage <usenet@morrow.me.uk>
Re: float storage ctcgag@hotmail.com
Re: Help with a "Post" procedure. <matthew.garrish@sympatico.ca>
Re: I need help with an 'if statement' in perl (Malcolm Dew-Jones)
Re: Keypress automation? <ebohlman@omsdev.com>
Lost post (Shalini Joshi)
Re: Lost post <noreply@gunnar.cc>
Re: Lost post <postmaster@castleamber.com>
Re: Lost post <matthew.garrish@sympatico.ca>
Re: perl wrapper to limit stderr to first 1000 lines? <mhunter@berkeley.edu>
Problem with CGI Cookies and Redirects (Chris Haupt)
Re: Problem with CGI Cookies and Redirects <scott_m_stearns@yahoo.com>
Re: Problem with CGI Cookies and Redirects <noreply@gunnar.cc>
Random letters, getting same results <jasonp@monmouth.com>
Re: sorting text <ebohlman@omsdev.com>
Re: sorting text jamasd@hotmail.com
Re: sorting text <noreply@gunnar.cc>
Text Parsing (Shalini Joshi)
Re: text parsing <pinyaj@rpi.edu>
Re: text parsing <noreply@gunnar.cc>
Re: text parsing (Shalini Joshi)
Re: text parsing (Shalini Joshi)
Re: while grep filehandle <Joe.Smith@inwap.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 18 Jun 2004 16:10:26 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: "antispam" perl mods?
Message-Id: <40d35a42$0$199$58c7af7e@news.kabelfoon.nl>
bad_knee wrote:
> I'm looking for a way to check mail on a pop3 server against something
> like a Spamcop (http://www.spamcop.net/bl.shtml> blacklist before I
> download it.
> Anyone have some simple ideas?
>
> I tried building Spamassassin on solaris 9 sparc yesterday and make
> test produced
> a lot of errors about versions. Upgraded to perl5.8 and of course now
> have to download/rebuild all the extra modules added in 5.6. I bet
> there is an easier way to do this?
Go with SpamAssassin, it's great, and does much more than blacklist
checking. You can add your own rules, see
http://johnbokma.com/spam/spamassassin-cookbook.html
for some examples.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Fri, 18 Jun 2004 15:04:16 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: $NF for perl
Message-Id: <remorse-4D47B8.15041518062004@plato.harvard.edu>
In article <cav2b6$m3n$1@mamenchi.zrz.TU-Berlin.DE>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> Richard Morse <remorse@partners.org> wrote in comp.lang.perl.misc:
> > In article <Pine.A41.4.58.0406051847200.7498@ginger.libs.uga.edu>,
> > Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
> >
> > > And the assignment to $n... provides the scalar context, so scalar() isn't
> > > needed. There are good reasons not to use scalar() when it isn't needed.
> >
> > What would such reasons be? I often use it for clarity's sake even when
> > it isn't strictly necessary -- what side effects does it have that might
> > be invidious? `perldoc -f scalar` and `perldoc -q scalar` don't seem to
> > note any deleterious side effects...
>
> I am strongly opposed to adding stuff to code "for clarity's sake", even
> if it provably doesn't hurt.
>
> For one, it doesn't accomplish its purpose. The process of understanding
> code is largely understanding why every bit is where it is. If some bits
> are there just because the author liked it that way, that makes this
> process harder, not easier. That goes for scalar() when context is already
> scalar as well as for unnecessary quoting of variables, unnecessary escaping
> in strings and regexes, unnecessary variable initializations and a host
> of less frequent unnecessarities.
As an example, I prefer the following:
my $var = scalar(@array);
instead of:
my $var = @array;
because it explicates that I'm interested in the size of the array --
and makes it obvious that I didn't mistype the sigil in front of 'var'.
I also, on the few occasions when I use c-style loops, prefer:
for (my $i = 0; $i < scalar(@array); $i++) {
}
although the reason for this doesn't spring to mind -- probably because
it's how I taught myself (I only discovered this forum a few months
back, although I have been programming in Perl for about five years now).
I don't really see that either of these two cases makes it harder to
understand the code -- in fact, when I'm reading over it really quickly,
it makes it easier...
Ricky
------------------------------
Date: Sat, 19 Jun 2004 00:53:52 +0200
From: Michael Krueger <kruger@math.fu-berlin.de>
Subject: Re: Encoding question
Message-Id: <Pine.LNX.4.44.0406190050570.30661-100000@vader.inf.fu-berlin.de>
On Fri, 18 Jun 2004, Ben Morrow wrote:
>
> Quoth Michael Krueger <kruger@math.fu-berlin.de>:
> > Hi,
> > I have a text based application and want to draw some kind of frame, on
> > the screen. OS is Debian/Linux using Perl 5.6
> >
> > I'm using this code:
> >
> > -- snip ---
> > my $top = chr(201);
> > my $bottom = chr(200);
> > for (my $i = 0; $i < ($termCols-2); $i++)
>
> for my $i (0 .. ($termCols-2)) {
>
> is much more Perlish...
>
> > {
> > $top .= chr(205);
> > $bottom .= chr(205);
> > }
> > $top .= chr(187);
> > $bottom .= chr(188);
>
> ...but even more so would be
>
> my $top = chr(201) . (chr(205) x ($termCols - 2)) . chr(187);
>
> > $term->Tgoto('cm', 0, 0, *STDOUT);
>
> I'm not sure which class these methods are from, but you might consider
> using Term::ANSIScreen instead...
>
> > print $top;
> > for (my $i = 1; $i < ($termRows-1); $i++)
> > {
> > $term->Tgoto('cm', 0, $i, *STDOUT);
> > print chr(186);
> > $term->Tgoto('cm', $termCols-1, $i, *STDOUT);
> > print chr(186);
> > }
> > $term->Tgoto('cm', 0, $termRows-2, *STDOUT);
> > print $bottom;
> > -- snip --
> >
> > Where $termCols and $termRows are the current terminal lines and columns.
> >
> > Problem:
> > Due to the encoding to latin-1 charset I didn't get the expected
> > frame-symbols but some other accentuated(?) chars.
>
> The first thing to say is that if you want to mess with encodings,
> upgrade to perl 5.8. 5.8 supports Unicode properly, and through that all
> other encodings. The encoding pragma you mention only works in 5.8 (and
> doesn't do what I think you think it does: it changes the encoding your
> *program source* is considered to be in: i.e. the encoding of string
> literals in the source).
>
> There are, potentially, three encodings in use here: the one perl uses
> to convert the numbers in your source into characters, the one perl uses
> to convert the characters back to numbers again to send to the terminal,
> and the one the terminal uses to decide which glyph to draw.
>
> An easy and straightforward way to get rid of the first is the use
> "\N{...}" instead of chr, and look up the correct characters in the Big
> Ol' Unicode Character List <http://www.unicode.org/charts/>. You control
> the second using the :encoding layer on filehandles: see perldoc -f
> binmode, perldoc PerlIO::encoding.
>
> The third is I think your problem here: your terminal is expecting
> Latin-1 (entirely usual in the Unix world) and there are no box drawing
> characters in Latin-1. Your best answer is to persuade your terminal to
> want utf8 instead (unicode_start on the console, xterm -u8, most other
> terminal emulators will support it with an option); then you can call
> binmode STDOUT, ':utf8' and use the Unicode box-drawing characters.
>
> Ben
>
> --
> $.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
> $x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
> {$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t # ben@morrow.me.uk
> $J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.
>
Hi,
thx for your fast reply, this really helped me alot.
I'll try it with Unicode then.
Just want to draw those darn boxes ; )
michael
------------------------------
Date: 18 Jun 2004 14:37:33 -0700
From: ivo.welch@anderson.ucla.edu (ivo welch)
Subject: float storage
Message-Id: <5159bba2.0406181337.4804cccd@posting.google.com>
hi perl gurus: I would like to read about 1GB of floats, not doubles.
Does perl have the facility to designate internal storage of an array
to be in float (4-byte), not double (8-byte) representation?
Otherwise, I am running out of memory...
sincerely, /iaw
------------------------------
Date: Fri, 18 Jun 2004 23:24:07 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: float storage
Message-Id: <cavtin$ofb$1@wisteria.csv.warwick.ac.uk>
Quoth ivo.welch@anderson.ucla.edu (ivo welch):
> hi perl gurus: I would like to read about 1GB of floats, not doubles.
> Does perl have the facility to designate internal storage of an array
> to be in float (4-byte), not double (8-byte) representation?
> Otherwise, I am running out of memory...
No. NVs (Perl's representation of floating-point) are always NVs.
You could perhaps achieve this by writing a little XS or Inline class to
tie an array to a C float[]; something like (completely untested):
Tie/FloatArray.xs:
/* standard XS stuff */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
typedef struct floatarray {
UV size;
float *data;
} *Tie_FloatArray;
void extend_floatarray(Tie_FloatArray this, UV size)
{
this->size = size;
Renewc(this->data, this->size ? this->size : 1, float, float *);
}
/* note that the line below has a literal tab in the middle */
TYPEMAP
Tie_FloatArray T_PTROBJ_SPECIAL
INPUT
T_PTROBJ_SPECIAL
if (sv_derived_from($arg, \"${(my $ntt=$ntype)=~s/_/::/g;\$ntt}\")) {
IV tmp = SvIV((SV*)SvRV($arg));
$var = ($type) tmp;
}
else
croak(\"$var is not of type ${(my $ntt=$ntype)=~s/_/::/g;\$ntt}\")
OUTPUT
T_PTROBJ_SPECIAL
sv_setref_pv($arg, \"${(my $ntt=$ntype)=~s/_/::/g;\$ntt}\", (void*)$var);
MODULE = Tie::FloatArray PACKAGE = Tie::FloatArray
Tie_FloatArray
TIEARRAY (char *class)
CODE:
Newc(434, RETVAL, 1, struct floatarray, Tie_FloatArray);
RETVAL->size = 0;
Newc(434, RETVAL->data, 1, float, float *);
OUTPUT:
RETVAL
SV *
FETCH (Tie_FloatArray this, UV index)
CODE:
if (index < this->size) {
RETVAL = NEWSV(434, 0);
sv_setnv(RETVAL, this->data[index]);
}
else {
RETVAL = &PL_sv_undef;
}
OUTPUT:
RETVAL
float
STORE (Tie_FloatArray this, UV index, float value)
CODE:
if (index > this->size) {
croak("index %"UVf" > size %"UVf" of Tie::FloatArray",
index, this->size);
}
RETVAL = this->data[index] = value;
OUTPUT:
RETVAL
UV
FETCHSIZE (Tie_FloatArray this)
CODE:
RETVAL = this->size;
OUTPUT:
RETVAL
void
STORESIZE (Tie_FloatArray this, UV size)
CODE:
extend_floatarray(this, size);
void
EXTEND (Tie_FloatArray this, UV size)
CODE:
extend_floatarray(this, size);
void
DESTROY (Tie_FloatArray this)
CODE:
Safefree(this->data);
Safefree(this);
Note that this array *only* supports float values: no undefs.
Ben
--
I've seen things you people wouldn't believe: attack ships on fire off
the shoulder of Orion; I watched C-beams glitter in the dark near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. ben@morrow.me.uk
------------------------------
Date: 19 Jun 2004 00:36:49 GMT
From: ctcgag@hotmail.com
Subject: Re: float storage
Message-Id: <20040618203649.993$HC@newsreader.com>
ivo.welch@anderson.ucla.edu (ivo welch) wrote:
> hi perl gurus: I would like to read about 1GB of floats, not doubles.
What do you mean by 1 GB? 1GB the way C would store them, at 4 bytes each?
1GB of text representing floats, at ~20 bytes each?
> Does perl have the facility to designate internal storage of an array
> to be in float (4-byte), not double (8-byte) representation?
That's probably the least of your problems. All the reference counts and
flags and double indirection and etc. that make up perl data internally is
much larger that the 4 byte difference you are talking about. I'd
consider about 20 bytes per float to be the absolute minimum you can get
out of perl, and that is if you are very careful.
> Otherwise, I am running out of memory...
PDL might have something to help you out here. I don't really know PDL, so
I can't tell you more than that.
I often pack floats into strings, then pass the string to Inline::C
subroutines, where I cast the char* back to a float*. This works
especially well if Perl doesn't even need the floats, it just has to hold
onto them between Inline::C calls.
But really, your best bet is probably to spend your time changing the
algorithm so it doesn't need all data to be in memory at once. Otherwise,
when the problem size increases by 10%, all of your micro-tweaking effort
goes out the window and you are back to OOM errors again.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Fri, 18 Jun 2004 17:34:23 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Help with a "Post" procedure.
Message-Id: <kfJAc.57042$7H1.1877365@news20.bellglobal.com>
"Jim Simpson" <jimsimpson@cox.net> wrote in message
news:wgFAc.791$HN5.60@lakeread06...
> I am trying to automate logging in to an HTTPS site which requires a
"user
> name" and "password". It appears to me that the following code should do
the
> job - but it does not do it. Can someone help me out on this.
>
> I'm especially concerned about the "post" line. I do not understand what
> should be in the places where I have used 'text', 'password' and 'submit'.
>
You need to take a step back and learn some basic html. When you submit a
form, each field has (should have!) a name (i.e., <input name="somthing">)
which is used to identify the variable(s) being sent to the server. Username
and password are often used for fields on login pages, but no one says they
have to be. You need to read the source of the page you're trying to log on
to and see what variables actually need to be sent. You can then modify the
post line to send the correct name/value pairs (i.e., fieldname => 'value').
Matt
------------------------------
Date: 18 Jun 2004 11:43:38 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: I need help with an 'if statement' in perl
Message-Id: <40d337da@news.victoria.tc.ca>
Sam (samuelvange@cox.net) wrote:
: I have a .cgi script on my website and (I think) it's written in perl.
: I know some c++ and as far as I can tell this is the drop down menu
: on my store.cgi page:
: </ul>
: <!-- VF begin client add search params form -->
: <form action="$script_url" method="post">
: List by Collection<br>
: <select name="collection"><option>Select</option>|;
: @collections=&get_collections;
: foreach $collection (@collections) {print
: "<option>$collection</option>";}
(why am i doing this?) untested
foreach $collection (@collections)
{
if ( $collection =~ m/^Collection$/ )
{
print "<option>Ken edwards collection</option>";
}else
{
print "<option>$collection</option>";
}
}
: print qq | </select>
: <input type="submit" value="Search">
: I have a list of items categorized by collection. One of these is
: simply called 'collection' (where as the others have names like
: 'ceramic collection', 'glassware collection', etc.).
: *What I need to do is have the drop down menu list all of these
: categories, and for the group that is simply called 'collection', I'd
: like it to display 'Ken Edwards collection'. For example:
: change
: ____________________________ that's the
: Ceramic collection |\/| <-down arrow on the drop down menu
: Figurine collection |
: Collection | *This line needs to change
: Glassware collection________|
: to
: ____________________________
: Ceramic collection |\/|
: Figurine collection |
: Ken edwards collection | *This line needs to change
: Glassware collection________|
: I assume this can be done with an if statement, but I can't do it.
: Thanks in advance
: PS:I sell Mexican crafts, and I'm looking for reciprocal links, if
: your interested please email me. I wont plug myself here, but I'll
: email you my website if youd like.
: Thanks again
: Sam
--
(Paying) telecommute programming projects wanted. Simply reply to this.
------------------------------
Date: 18 Jun 2004 19:48:30 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: Keypress automation?
Message-Id: <Xns950C97526852Aebohlmanomsdevcom@130.133.1.4>
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
news:cav2j6$3c4$1@canopus.cc.umanitoba.ca:
> If it is MS Windows... I don't know. My little- enough- to- be- dangerous
> reading would suggest that if you had a service which had been given
> permission to interact with the desktop, that you could perhaps
> accomplish what you want. It's not too different from what some of the
> installers have to do sometimes.
If it's MS-Windows, use the SendKeys function from Win32::GUITest.
------------------------------
Date: 18 Jun 2004 14:17:45 -0700
From: shalinij1@yahoo.com (Shalini Joshi)
Subject: Lost post
Message-Id: <283d6b7e.0406181317.f32c302@posting.google.com>
Hi. I posted a message on the group this morning. But I cant see
it(for following up on the replies- which i got through email) on the
group or even if i perform a search on the group.
Is it lost ?
I'd appreciate if someone could tell me how to get my post back??
Thanks.
Shalini
------------------------------
Date: Fri, 18 Jun 2004 23:28:00 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Lost post
Message-Id: <40D35E60.5020002@gunnar.cc>
Shalini Joshi wrote:
> I posted a message on the group this morning. But I cant see it
If you are referring to a message you posted at 17:43 UTC, it's
available on the news server I'm using together with Jeff's reply. If
you are looking for them in Google Groups, please note that they will
be displayed there only after several hours.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 18 Jun 2004 16:29:14 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Lost post
Message-Id: <40d35eaa$0$211$58c7af7e@news.kabelfoon.nl>
Shalini Joshi wrote:
> Hi. I posted a message on the group this morning. But I cant see
> it(for following up on the replies- which i got through email) on the
> group or even if i perform a search on the group.
>
> Is it lost ?
>
> I'd appreciate if someone could tell me how to get my post back??
Google is slow, hours.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Fri, 18 Jun 2004 17:24:15 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Lost post
Message-Id: <%3JAc.56954$7H1.1873353@news20.bellglobal.com>
"Shalini Joshi" <shalinij1@yahoo.com> wrote in message
news:283d6b7e.0406181317.f32c302@posting.google.com...
> Hi. I posted a message on the group this morning. But I cant see
> it(for following up on the replies- which i got through email) on the
> group or even if i perform a search on the group.
>
> Is it lost ?
>
> I'd appreciate if someone could tell me how to get my post back??
>
Takes time for messages to propagate through the ether, and the google
archives are a particularly bad way to follow current discussions. I suppose
you could always unsubscribe from the group and then re-download all the
message headers and see if it's there. Otherwise you just need a little
patience. I can see it, and so obviously can a number of other people, so
whatever you do just don't post it again... : )
Matt
------------------------------
Date: Fri, 18 Jun 2004 18:40:15 +0000 (UTC)
From: Mike Hunter <mhunter@berkeley.edu>
Subject: Re: perl wrapper to limit stderr to first 1000 lines?
Message-Id: <slrncd6dks.10c.mhunter@celeste.net.berkeley.edu>
On Fri, 18 Jun 2004 01:54:49 +0000 (UTC), Ben Morrow wrote:
>
> Quoth mhunter@uclink.berkeley.edu:
> >
> > I have some cron jobs that can sometimes send out too much noise to stderr,
> > which in turn causes sendmail to do bad things :( I'm trying to limit the
> > amount of stderr I see from those scripts without changing the scripts
> > themselves. I am looking to write a perl wrapper that does something like this:
> >
> > my $program = shift @ARGV;
> > my $args = join " ", @ARGV;
>
> What's the point of shifing @ARGV if you're just going to join
> "$program " onto the beginning anyway?
Just thinking ahead :)
> > open PGMSTDOUT, "$program $args|" or die "blah!";
>
> Don't do this: use three-arg open.
> Use lexical file-handles.
>
> open my $PGMSTDOUT, '-|', @ARGV or die "can't run $ARGV[0]: $!";
>
> > while (<PGMSTDOUT>)
> > {
> > print $_;
> > }
> >
> > my $n = 0;
>
> Perl provides the special variable $. for this job. See perldoc perlvar.
Thanks.
> > my $error_line = <PGMSTDERR>;
> > while (<PGMSTDERR> && ($n < 1000))
>
> This is wrong: Perl does special magic with while (<>). What you mean is
>
> while (<PGMSTDERR>) {
> $. > 999 and last;
>
> or
>
> while (defined($_ = <PGMSTDERR>) and $. < 1000) {
>
> which is what perl expands while (<>) into.
>
> > {
> > $error_line = <PGMSTDERR>;
>
> Presumably you are reading again because you lost the results when you
> lost the magic while (<>); this will discard every other line, though.
Yeah, my bad.
> > print STDERR $error_line;
> > $n++;
> > }
> >
> > The only similar advice I've seen on the web was here:
> >
> > http://perlmonks.thepen.com/730.html
> >
> > But I don't want to follow that approach because I don't want to create a file
> > on disk with all the STDERR stuff, I want to discard it.
> >
> > Any help? How do I *pipe* stderr to something without duping it to stdout?
>
> If you simply want to discard all of stderr, use 2>/dev/null in the
> command line. If you want to grab stdout and stderr separately, you
> will need to use IPC::Open3; you will also need to use IO::Select to
> process the bits of each as they arrive, or you'll get deadlocks (you'll
> be waiting for the end of stdout, the program will be blocking trying to
> write something to stderr).
Thanks, I'll look into those. I knew it wouldn't be easy :)
Mike
------------------------------
Date: 18 Jun 2004 15:01:46 -0700
From: haupt@onlinesports.com (Chris Haupt)
Subject: Problem with CGI Cookies and Redirects
Message-Id: <15360fc5.0406181401.60698a64@posting.google.com>
We have a script using the CGI module which sets a cookie and then
performs a redirect:
print $q->redirect($url, -cookie=>$cookie) ;
In version 2.81 of CGI this works fine. When we upgraded to 3.05
recently this stopped working. In Explorer when I run this script I
get the following error:
Internet Explorer doesn't know how to handle the type of file you have
selected
You can choose to save this file to your disk or you can configure a
Helper Application for this file.
MIME TYPE: application/x-httpd-cgi
File Name: goto.cgi
Using the cookie in the header function (e.g. print $q->header(
-cookie=>$cookie)) works fine in 3.05 so the problem appears to be
with the use of cookies in the redirect method.
We've backed up to version 2.81 but I'd like to get back to 3.05 if
this problem can be resolved.
Thanks,
Chris
------------------------------
Date: 19 Jun 2004 00:31:45 GMT
From: Scott Stearns <scott_m_stearns@yahoo.com>
Subject: Re: Problem with CGI Cookies and Redirects
Message-Id: <Xns950CC75603035scottmstearnsyahooco@209.98.13.60>
haupt@onlinesports.com (Chris Haupt) wrote in news:15360fc5.0406181401.60698a64@posting.google.com:
> We have a script using the CGI module which sets a cookie and then
> performs a redirect:
> print $q->redirect($url, -cookie=>$cookie) ;
>
> In version 2.81 of CGI this works fine. When we upgraded to 3.05
> recently this stopped working. In Explorer when I run this script I
> get the following error:
> Internet Explorer doesn't know how to handle the type of file you have
> selected
>
> You can choose to save this file to your disk or you can configure a
> Helper Application for this file.
>
> MIME TYPE: application/x-httpd-cgi
> File Name: goto.cgi
>
> Using the cookie in the header function (e.g. print $q->header(
> -cookie=>$cookie)) works fine in 3.05 so the problem appears to be
> with the use of cookies in the redirect method.
>
> We've backed up to version 2.81 but I'd like to get back to 3.05 if
> this problem can be resolved.
>
> Thanks,
>
> Chris
>
I did a couple tests using CGI.pm 3.01 but I found something that might be of interest assuming it also happens in 3.05.
Using this code-line:
print $q->redirect(-uri => $url, -cookie => $cookie);
the output on the command-line is:
-->./redirect.pl
Status: 302 Moved
Set-Cookie: redirectTest=redirectValue; path=/; expires=Sat, 19-Jun-2004 01:22:4
8 GMT
Date: Sat, 19 Jun 2004 00:22:48 GMT
Location: http://www.yahoo.com/
-->
Using this code-line (from OP's post):
print $q->redirect($url, -cookie => $cookie);
the output on the command-line is:
-->./redirect.pl
Status: 302 Moved
Window-Target: -cookie
Set-Cookie: redirectTest=redirectValue; path=/; expires=Sat, 19-Jun-2004 01:24:0
4 GMT
Date: Sat, 19 Jun 2004 00:24:04 GMT
Location: http://www.yahoo.com/
-->
Notice the 'Window-Target' header line. Doesn't seem like this would cause the error you mentioned but I figured I'd mention it.
-Scott
------------------------------
Date: Sat, 19 Jun 2004 02:40:55 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Problem with CGI Cookies and Redirects
Message-Id: <2jhgd6F119larU1@uni-berlin.de>
Chris Haupt wrote:
> We have a script using the CGI module which sets a cookie and then
> performs a redirect:
> print $q->redirect($url, -cookie=>$cookie) ;
>
> In version 2.81 of CGI this works fine. When we upgraded to 3.05
> recently this stopped working.
Try this:
print $q->redirect(-location=>$url, -cookie=>$cookie);
-----------------------^^^^^^^^^^^
Even if it requires some guesswork, it appears as if you need to state
the -location parameter explicitly when you use CGI.pm's redirect()
method for printing other headers.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 18 Jun 2004 20:25:13 -0400
From: LANkrypt0 <jasonp@monmouth.com>
Subject: Random letters, getting same results
Message-Id: <Pine.LNX.4.58.0406182010300.32244@localhost.monmouth.com>
I wrote the following little script below and am running into a problem.
The script with an argument:
./script.pl hello
It then would get the length of the word hello and use that to generate
random letters of that amount. i.e, doiqw
Then it SHOULD keep running until the word hello is matched with a one of
the random outputs. The problem is that it outputs the same results, i.e
doiqw
doiqw
doiqw
etc.
Any help or insight into why this is happening would be greatly
appreciated. Also any tips on better coding practices or streamlining
this is also appreciated =)
Thanks!
==+ BEGIN CODE +==
#!/usr/bin/perl
use strict;
my $counter = 0;
my $attempts = 0;
my $word;
my $tword;
sub wordcheck #Checks if word matches, if so print and exit
{
if ($word eq $ARGV[0])
{
print "Word found in $attempts attempts!\n";
exit
}
}
sub getword #Generates random letters, length based on $ARGV[0] length
{
while ($counter < length($ARGV[0]))
{
$tword = chr(int(rand(ord("z")-ord("a"))+ord("a")));
$word = $tword.$word;
$counter++;
}
}
while ($word ne $ARGV[0]) #Runs until matches
{
getword
print "$word\n";
wordcheck
$attempts++
}
==+ END CODE +==
--
LANkrypt0 :: aa#2118
------------------------------
Date: 18 Jun 2004 19:26:10 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: sorting text
Message-Id: <Xns950C93891DD6Febohlmanomsdevcom@130.133.1.4>
John Bokma <postmaster@castleamber.com> wrote in
news:40d0fc45$0$205$58c7af7e@news.kabelfoon.nl:
>>>Don't see any point in putting the constant to the left, btw. Silly C
>>>coding convention IIRC.
>>
>> There's nothing wrong with it. It's not "silly". There is a point
>> to it. It stops you from accidentally writing = instead of == if you
>> mean to do a comparison. Compare:
>>
>> if ($foo = 2) { ... }
>
> Found = in conditional, should be ==
>
>> The coder *meant* to write ==, but only did =. The first one is not
>> an error, and the if block is reached all the time. The second one
>> IS an error.
>
> No, it's and error if your compiler, interpreter, etc doesn't *WARN*
> you. And a programmer turning of those warnings is silly.
>
> Most C, C++ compilers do warn, as does Perl (with use strict, use
> warnings). It is IMNSHO a stupid coding convention, illogical,
> unreadable, weird. Especially with *inequalities* as the prev post
> used.
Whether or not one adopts (or is forced by local coding standards to adopt)
that particular convention with regard to tests for equality, it's
ridiculously rigid to invert the sense of relational comparisons for no
other reason than "putting the constant on the left." That really smacks
of a failure to think abstractly leading to an inability to distinguish
means from ends. In this case, the means that *may* help to achieve the
end of making equality comparisons less error-prone winds up, when applied
blindly, making other kinds of comparisons *more* error-prone.
------------------------------
Date: 18 Jun 2004 12:41:09 -0700
From: jamasd@hotmail.com
Subject: Re: sorting text
Message-Id: <3151a273.0406181141.33f039d@posting.google.com>
jamasd@hotmail.com wrote in message news:<3151a273.0406171746.4104539f@posting.google.com>...
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2jedptF107b39U1@uni-berlin.de>...
> > jamasd@hotmail.com wrote to comp.lang.perl.modules:
> > > Here is a sample of my data (each column is separated by tabs):
> >
> > What the h... Yesterday you posted the same question to
> > comp.lang.perl.misc, and several people have helped you. Why are you
> > repeating the original question now in comp.lang.perl.modules??? (And
> > how is your question related to the use of Perl modules?)
>
>
> Also, I didnt realize there was a delay in posting (I didnt read the
> thing following a post which was stupid on my part). I was wondering
> why it wasnt posting.
Here is what I have so far. Right now it is printing out the entire
file in one line. I want it to print each line that matches
individually, in the same format they were in.
Here is the file again
1234123 jaesdf ytkyk 345234
1264345 ghgfdf ghjhg 657658
3456765 sdasdf ytkyk 456543
1231232 assffg werwe 123454
5447454 asdqfr ytkyk 254364
my ( $buffer , @fields , $filename , %hash1 );
$filename = 'Untitled.rtf';
open(INPUT, "< $filename") or die("Can't open file \"$filename\" :
$!\n");
%hash1 = ( "ytkyk" => 1 , "ghjhg" => 1 );
while ( $buffer = <INPUT> ) {
chomp $buffer;
@fields = split(/\t+/,$buffer);
next if @fields < 3;
unless ( exists $hash1{$fields[2]} ) {
next;
} print "$buffer\n";
}
close INPUT;
i think it might need a foreach so it reads each line indivually.
------------------------------
Date: Fri, 18 Jun 2004 23:17:35 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: sorting text
Message-Id: <2jh4fqF10ihidU1@uni-berlin.de>
jamasd@hotmail.com wrote:
> Right now it is printing out the entire file in one line.
??
Please show us the *whole* program that gives that result.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 18 Jun 2004 14:58:13 -0700
From: shalinij1@yahoo.com (Shalini Joshi)
Subject: Text Parsing
Message-Id: <283d6b7e.0406181358.3b09eea4@posting.google.com>
Hi!
Thanks Jeff!!
I cant seem to figure out why your code (as is) goes into an infinite
loop when I try and run it??
My initial approach was something like this:
$/='FPR';
<>; #empty record
while(<>){
chomp;
print $_ ;
(Obviously it doesnt do what i want it to do..was just trying it out
to see how it works)
THanks..
Shalini
------------------------------
Date: Fri, 18 Jun 2004 14:13:29 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Shalini Joshi <shalinij1@yahoo.com>
Subject: Re: text parsing
Message-Id: <Pine.SGI.3.96.1040618140428.336102B-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On 18 Jun 2004, Shalini Joshi wrote:
>I am relatively new to perl and am looking to parse a non-delimited
>text file. What I would like to do is out of this file of records
>which always begin with 'FPR' and could span multiple lines, extract
>only some relevant records.
>
>The criterion is the number denoted by characters 7 through 18..I have
>a vague idea how to go about parsing this, but with so much
>information(on the website and the other postings on the group) it's
>kind of confusing what the best way to do it is..I am initially
>interested in just getting the script to work...
It would be helpful if you showed us what code you're already trying.
The first thing I would do is read one 'record' from the file at a time.
You could use $/ to do this, but in your case it would be a little
trickier than usual, so I'll avoid that approach. Here, I'm just reading
until I get to a line that starts with "FPR".
my @records;
open RECORDS, "< file.txt" or die "can't read file.txt: $!";
# get the FIRST line of the record
local $_ = <RECORDS>;
{
# put the first line into $rec
my $rec = $_;
# get all subsequent lines of the record
while (<RECORDS>) {
# stop if we encounter an FPR line
last if /^FPR/;
# tack this line onto the $rec variable
$rec .= $_;
}
# add this record to the array
push @records, $rec;
# go back to the top of the block
# NOTE: at this point, $_ is the
# first line of the NEXT record
redo;
}
close RECORDS;
Now you have an array, @records, that contains the FPR-marked records in
your file. What you do with that array is up to you.
--
Jeff Pinyan RPI Acacia Brother #734 RPI Acacia Corp Secretary
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Sat, 19 Jun 2004 01:09:07 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: text parsing
Message-Id: <40D37613.4010802@gunnar.cc>
Shalini Joshi wrote:
> I am relatively new to perl and am looking to parse a non-delimited
> text file. What I would like to do is out of this file of records
> which always begin with 'FPR' and could span multiple lines,
> extract only some relevant records.
>
> The criterion is the number denoted by characters 7 through 18..
Not easy to suggest anything without sample data, but how about
something like this:
open OLDFILE, $oldfile or die $!;
open NEWFILE, "> $newfile" or die $!;
{
local $/ = 'FPR';
print NEWFILE scalar <OLDFILE>;
while (<OLDFILE>) {
my $num = substr ($_, 3, 12;
if ( ... some tests of $num ... ) {
print NEWFILE $_;
}
}
}
close NEWFILE;
close OLDFILE;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 18 Jun 2004 16:36:06 -0700
From: shalinij1@yahoo.com (Shalini Joshi)
Subject: Re: text parsing
Message-Id: <283d6b7e.0406181536.28a5e403@posting.google.com>
I also have the following data from the data file:
Sorry for not including all the information in one post. Will keep all
this in mind in all my future ones.
RHR001PRICE REFRESHER2004052620040526*AETNA*V (Header)
FPR001AET001A20AET81082004052601863063601863063600000000000ING VP
Growth and Income M&E 1.40% (Data)
FPR001AET001A70AETN2062004052601384691901384691900000000000ING VP
Growth and Income M&E 1.40% (Data)
RTR001PRICE REFRESHER000000569 (Trailer)
Of course the data doesnt wrap in the file..it's one single line(funny
when i print it on paper it gave me the data on multiple lines).
I am not sure why the code in Jeff's reply doesnt work..when i run it
it just sits in an infinite loop. I have to kill it to get back to my
prompt.
THanks for all the helpful posts.
Regards
Shalini
------------------------------
Date: 18 Jun 2004 17:38:52 -0700
From: shalinij1@yahoo.com (Shalini Joshi)
Subject: Re: text parsing
Message-Id: <283d6b7e.0406181638.6e70a35@posting.google.com>
Hi ..this is regarding my earlier post.
I got it working.Apparently because of the redo, it was going into an
infinite loop. Here's what i did and it works when I print out the
array elements now.
#! /usr/bin/perl
use strict;
my @records;
my $i;
open RECORDS, "< AETNA17.R3617.txt" or die "Can't read file:
$!";
# Get the first line of the record
local $_ = <RECORDS>;
#print $_ ;
while (<RECORDS>){
#Put the first line into $rec
my $rec = $_;
#get all subsequent lines of the record
while (<RECORDS>) {
# stop if we encounter an FPR line
last if /^FPR/;
# tack this line onto the $rec variable
$rec .= $_;
}
push @records, $rec;
#Go back to the top of the block
# At this point, $_ is the first line of the NEXT FPR record
print "$_";
}
pop @records; # To remove the trailer that is stored before
condition
# is tested
close RECORDS;
foreach $i (@records)
{
print "$i";
}
Am now working on dealing with the array elements.
Thanks a bunch for the help.
Regards,
Shalini
------------------------------
Date: Fri, 18 Jun 2004 19:26:33 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: while grep filehandle
Message-Id: <JlHAc.69864$HG.55522@attbi_s53>
Juha Laiho wrote:
>> while ( grep /Results/, <IN> ) {
>> print "$_\n";
>> }
>
> My brain fails as to why the above doesn't work,
There's a big difference between
foreach ( grep /Results/, <IN>) { print }
and
while ( grep /Results/, <IN>) { print }
-Joe
------------------------------
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 6706
***************************************