[21750] in Perl-Users-Digest
Perl-Users Digest, Issue: 3954 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 11 11:06:11 2002
Date: Fri, 11 Oct 2002 08:05:11 -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, 11 Oct 2002 Volume: 10 Number: 3954
Today's topics:
Re: Any way around using the $& variable? <usenet@tinita.de>
Re: Any way around using the $& variable? (Peter J. Acklam)
Re: Anyone who uses Perl on VAX (Ph3arnot)
Re: Bug or weird thing? <dd@4pro.net>
Re: Fork question? (paul)
grep list from a list <yossi_shani@yahoo.com>
Help w/ Perl script on Apache Server <drbojxn@netdoor.com>
Re: Help w/ Perl script on Apache Server <flavell@mail.cern.ch>
Re: Need to convert from seconds since Unix epoch to GM news@roaima.freeserve.co.uk
Re: Net::FTP: Unexpected EOF on command channel news@roaima.freeserve.co.uk
Re: Newbie: Simple but GOOD form handler - WHERE? news@roaima.freeserve.co.uk
pattern matching (Doggy)
Re: pattern matching <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: pattern matching <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: pattern matching (Doggy)
Re: pattern matching (Tad McClellan)
possible bug in AUTOLOAD with 5.8.0 <john.clutterbuck@siemens.com>
Re: Problem with require() versus in-line code <jan@klaverstijn.nl>
problems with PDF files and -T switch <rlogsdon@io.com>
Re: problems with PDF files and -T switch <flavell@mail.cern.ch>
Re: problems with PDF files and -T switch (Tad McClellan)
Re: Returning hashrefs <usenet@tinita.de>
Sendmail (GetWebWise)
Re: Sendmail (Helgi Briem)
Re: Should -i eat my files? (Tad McClellan)
Re: Synchronizing my perl processes <billy@arnis-bsl.com>
Re: The Perl Journal needs help <david.bouman@xo.nl>
ultiple "my" declaration <pef@trasig.noXX>
Re: ultiple "my" declaration (Helgi Briem)
Re: ultiple "my" declaration <DJMartin@DynaComp-Solutions.com>
Re: ultiple "my" declaration <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Re: ultiple "my" declaration (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Oct 2002 10:08:47 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Any way around using the $& variable?
Message-Id: <ao67vf$j8up8$1@fu-berlin.de>
Peter J. Acklam <pjacklam@online.no> wrote:
> I want to highlight the text matched by an arbitrary regex,
> but I can't find any way around using the $& variable in
> the substitution. Is there any way to avoid using it?
> Here is an stripped-down example script
> #!/usr/bin/perl -wp
> BEGIN { $regex = shift }
> s/$regex/\e[36m$&\e[m/go; # note the "$&"
> In the following example, "oo" and "arba" is colored:
> $ echo "foobarbaz" | ./tmp.pl '([oa]).*\1'
> foobarbaz
> Is there really no way around using $& in the substitution?
yes:
s/($regex)/\e[36m$1\e[m/go;
then you have to use '([oa]).*\2' instead of the \1
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 11 Oct 2002 07:43:00 -0700
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Any way around using the $& variable?
Message-Id: <fe4612a5.0210110643.14660e98@posting.google.com>
Tina Mueller <usenet@tinita.de> wrote:
> s/($regex)/\e[36m$1\e[m/go;
>
> then you have to use '([oa]).*\2' instead of the \1
Ok, so how to you shift all the backreferences in
an arbitrary regex?
Peter
------------------------------
Date: 11 Oct 2002 06:58:16 -0700
From: ph3arnot@hotmail.com (Ph3arnot)
Subject: Re: Anyone who uses Perl on VAX
Message-Id: <32b689fe.0210110558.1485a59f@posting.google.com>
pkent <pkent77tea@yahoo.com.tea> wrote in message news:<pkent77tea-58B773.01193910102002@news-text.blueyonder.co.uk>...
> In article <32b689fe.0210091048.250d0c2f@posting.google.com>,
> ph3arnot@hotmail.com (Ph3arnot) wrote:
>
> > An interesting note, the version of perl that is running on our
> > VAX/Alpha cluster DOESN'T have a "chomp" command. I haven't even
>
> Gah! OpenVMS and an ancient version (or bizarrely patched) of perl.
>
> What happens if you run 'perl -v' and 'perl -V' or whatever the
> equivalent is under the DCL shell? You should get information about the
> build of perl.
> Has your sysadmin installed several versions of perl, and you're
> accessing but one of them (apaprently perl 4 if its missing chomp()).
>
> P
There is only one install of perl on the cluster, so the issue isn't
one of logicals pointing to the wrong place.
As I had mentioned, it's not really worth worrying about on this
platform. All my perl programming is done on either Linux or NT
boxes, so I keep those up to date. :)
------------------------------
Date: Fri, 11 Oct 2002 08:54:31 -0400
From: "Domizio Demichelis" <dd@4pro.net>
Subject: Re: Bug or weird thing?
Message-Id: <ao6hnh$jq5q9$1@ID-159100.news.dfncis.de>
> So I guess it's a "weird thing", not a bug. :)
me too :-)
--
-.. --- -- .. --.. .. ---
-.. . -- .. -.-. .... . .-.. .. ...
------------------------------
Date: 11 Oct 2002 07:49:25 -0700
From: paulthomson@hotmail.com (paul)
Subject: Re: Fork question?
Message-Id: <464e478f.0210110649.694f9549@posting.google.com>
Thanks guys,
You have certainly given me much food for thought. Benjamin - thanks
for the code - that could very well save my hairline from receding for
a day or 2 :)
I have another quick question if anyone has an opinion. I may have to
send and receive many, many emails (possibly 100,000) for a period of
one month. It is for a web application and definitely not spam. The
previous application I mentioned sends SMS so this is a seperate app.
I have sent mail on a few occassions with Perl (libnet stuff, etc) but
wandered if anyone had any opinions on piping this amount of mail out
through SMPP (and receiving via pop3?).
Thanks again,
Paul
------------------------------
Date: Fri, 11 Oct 2002 17:01:01 +0200
From: "yossi shani" <yossi_shani@yahoo.com>
Subject: grep list from a list
Message-Id: <1034348478.98823@sj-nntpcache-3>
Greetings,
Maybe you could shed some light into this matter...
I have two lists, and I would like to find any of the components of the
@match list from the @name list,
I want to replace the hardcoded "(one|five)" with list.
mant thanks,
Yossi.
@name=qw(one two three four five);
@match = qw( one four );
# This is the working example but I would like to incorporate a list in the
regex area
if ( grep /^(one|five)$/, @name ) {
print "something...";
}
------------------------------
Date: Fri, 11 Oct 2002 07:48:39 -0500
From: "Bo Holloman" <drbojxn@netdoor.com>
Subject: Help w/ Perl script on Apache Server
Message-Id: <hIzp9.10496$CE4.836825@news.bellsouth.net>
I am using the following Perl script (redirect.pl) for redirection:
#!/usr/local/bin/perl
print ("Location: http://go.prewired.com/bhltvcom/bhltv_home\n\n");
exit ();
If I run the script directly from the browser, i.e.
http://www.bhltv.com/cgi/redirect.pl , the script works fine and redirection
occurs.
However, when I reference the script as a SSI in
http://www.bhltv.com/redirect.shtml, i.e.
<!--#exec cgi="/cgi/redirect.pl"-->
The sript inserts the following code into the HTML:
<A
HREF="http://go.prewired.com/bhltvcom/bhltv_home">http://go.prewired.com/bhl
tvcom/bhltv_home</A>
rather than activate the redirection transparently to the user.
Please, tell me what I am doing wrong. Does this have something to do with
Apache configuration? If so, can I fix it with .htaccess?
Bo Holloman
------------------------------
Date: Fri, 11 Oct 2002 15:06:07 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Help w/ Perl script on Apache Server
Message-Id: <Pine.LNX.4.40.0210111500260.2114-100000@lxplus071.cern.ch>
On Oct 11, Bo Holloman inscribed on the eternal scroll:
> print ("Location: http://go.prewired.com/bhltvcom/bhltv_home\n\n");
[..]
> However, when I reference the script as a SSI in
> http://www.bhltv.com/redirect.shtml, i.e.
>
> <!--#exec cgi="/cgi/redirect.pl"-->
it won't work.
> Please, tell me what I am doing wrong.
Aside from asking on the wrong group? You're trying to get SSI to do
something that it doesn't support.
To get the redirection to work, you need to invoke the URL of the CGI
script itself, from the client.
CGI is a published interworking specification. SSI is not, but rather,
a concept, which each server designer may implement in different ways.
Consult the specification for the server that you use to find out what
its SSI implementation supports.
Such questions would be more appropriate on
comp.infosystems.www.authoring.cgi or comp.infosystems.www.servers.*
since you don't appear to have any Perl-specific problem.
------------------------------
Date: Fri, 11 Oct 2002 11:24:59 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: Need to convert from seconds since Unix epoch to GMT
Message-Id: <rt86oa.9c8.ln@moldev.cmagroup.co.uk>
J Hall <gmnotyet@yahoo.com> wrote:
> Can someone easily tell me how to convert from seconds since
> the Unix epoch (midnight, Jan 1, 1970) to GMT?
my $gmt_seconds = $epoch_seconds;
Seconds since the epoch *is* GMT. (Well, actually it's UTC but do you
really need the difference?)
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: Fri, 11 Oct 2002 11:22:06 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: Net::FTP: Unexpected EOF on command channel
Message-Id: <eo86oa.9c8.ln@moldev.cmagroup.co.uk>
Villy Kruse <vek@station02.ohout.pharmapartners.nl> wrote:
> There can also be a problem with statefull firewalls when you are
> transferring big files. The firewall may notice that the command
> channel is sitting completely idle for a long time and then determine
> that the connection is in fact dead.
Yes, I've been bitten by this in the past. IMO, I would call this a bug
in the "statefulness" code; if it can handle active FTP then it should
be able to realise that data flow on the data connection implies a
(probably) idle command channel - and as such it shouldn't be timed out.
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: Fri, 11 Oct 2002 11:18:59 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: Newbie: Simple but GOOD form handler - WHERE?
Message-Id: <ji86oa.9c8.ln@moldev.cmagroup.co.uk>
Dan Vendel <newsgroups@vendel.info> quoted:
> "He who asks a question is a fool for five minutes; he who does not
> ask a question remains a fool forever."
> -Chinese Proverb
"He who asks a question without first reading the FAQ remains a fool
forever."
-Usenet truth
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: 11 Oct 2002 03:16:01 -0700
From: tru64dog@yahoo.com (Doggy)
Subject: pattern matching
Message-Id: <18239c3a.0210110216.4d066ebd@posting.google.com>
I have searched through the perldocs and my books but, probably due to
my ignorance, I'm not able to find a solution.
I would like to take the pattern below and only extract the email
address (everything between the ':' and '%' and put it in a variable.
Can someone give me a pointer.
$test = "SMTP:Marketing@dog.com%X400:";
Cheers
Tman
------------------------------
Date: Fri, 11 Oct 2002 10:46:12 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: pattern matching
Message-Id: <slrnaqdas5.7rm.bernard.el-hagin@gdndev25.lido-tech>
In article <18239c3a.0210110216.4d066ebd@posting.google.com>, Doggy
wrote:
> I have searched through the perldocs and my books but, probably due to
> my ignorance, I'm not able to find a solution.
>
> I would like to take the pattern below and only extract the email
> address (everything between the ':' and '%' and put it in a variable.
> Can someone give me a pointer.
>
> $test = "SMTP:Marketing@dog.com%X400:";
^^^^
Are you sure you want double quotes for $test?
my $test = 'SMTP:Marketing@dog.com%X400:';
my ($address) = $1 if $test =~ m/^[^:]*:([^%]+)%/;
print "The address is '$address'.\n";
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Fri, 11 Oct 2002 10:47:49 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: pattern matching
Message-Id: <slrnaqdav6.7rm.bernard.el-hagin@gdndev25.lido-tech>
In article <slrnaqdas5.7rm.bernard.el-hagin@gdndev25.lido-tech>,
Bernard El-Hagin wrote:
> In article <18239c3a.0210110216.4d066ebd@posting.google.com>, Doggy
> wrote:
>> I have searched through the perldocs and my books but, probably due to
>> my ignorance, I'm not able to find a solution.
>>
>> I would like to take the pattern below and only extract the email
>> address (everything between the ':' and '%' and put it in a variable.
>> Can someone give me a pointer.
>>
>> $test = "SMTP:Marketing@dog.com%X400:";
> ^^^^
>
>
> Are you sure you want double quotes for $test?
>
>
> my $test = 'SMTP:Marketing@dog.com%X400:';
>
> my ($address) = $1 if $test =~ m/^[^:]*:([^%]+)%/;
^ ^
Those parens are unnecessary, by the way. Just making sure you're
paying attention.
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: 11 Oct 2002 07:19:02 -0700
From: tru64dog@yahoo.com (Doggy)
Subject: Re: pattern matching
Message-Id: <18239c3a.0210110619.11e85366@posting.google.com>
Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in message news:<slrnaqdav6.7rm.bernard.el-hagin@gdndev25.lido-tech>...
> In article <slrnaqdas5.7rm.bernard.el-hagin@gdndev25.lido-tech>,
> Bernard El-Hagin wrote:
> > In article <18239c3a.0210110216.4d066ebd@posting.google.com>, Doggy
> > wrote:
> >> I have searched through the perldocs and my books but, probably due to
> >> my ignorance, I'm not able to find a solution.
> >>
> >> I would like to take the pattern below and only extract the email
> >> address (everything between the ':' and '%' and put it in a variable.
> >> Can someone give me a pointer.
> >>
> >> $test = "SMTP:Marketing@dog.com%X400:";
> > ^^^^
> >
> >
> > Are you sure you want double quotes for $test?
> >
> >
> > my $test = 'SMTP:Marketing@dog.com%X400:';
> >
> > my ($address) = $1 if $test =~ m/^[^:]*:([^%]+)%/;
Thank you; Bernard, please document so I can understand: ^[^:]*:([^%]+)%/
> ^ ^
>
>
> Those parens are unnecessary, by the way. Just making sure you're
> paying attention.
>
>
> Cheers,
> Bernard
------------------------------
Date: Fri, 11 Oct 2002 09:35:33 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: pattern matching
Message-Id: <slrnaqdodl.2g0.tadmc@magna.augustmail.com>
Doggy <tru64dog@yahoo.com> wrote:
> please document so I can understand: ^[^:]*:([^%]+)%/
/^ # beginning of string
[^:]* # any (includes zero) non-colon characters
: # colon character
( # remember matched chars in $1
[^%]+ # at least one non-percent character
) # stop remembering
% # percent character
/x; # eXtended regex option
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 11 Oct 2002 13:14:38 +0100
From: John Clutterbuck <john.clutterbuck@siemens.com>
Subject: possible bug in AUTOLOAD with 5.8.0
Message-Id: <3DA6C0AE.8050604@siemens.com>
I think we have found a bug with AUTOLOAD in perl 5.8.0 but there may be
another explanation. It certainly has some wierd behavour.
I would be grateful if someone could either explain the behavour and how
to overcome it, or confirm this is a bug so I can submit it.
AUTOLOAD is failing to get called for sub calls of the form Xxxx->new
when the class Xxxx has never been seen before.
Calls of Xxxx::new invoke AUTOLOAD correctly.
I have an example where having a LATER line in the code
of the form: Xxxx::foobar makes AUTOLOAD trigger correctly
for the prior line of Xxxx->new. Commenting out this line makes the
earlier line fail. This seems bizarre behavour.
Does this mean something is occuring at compile time.
This behavour occurs on perl 5.8.0(IRIX + Linux) but does
not occur on perl 5.6.1(Win32 - SeiPerl).
This is creating a big problem for us as we have hundreds of calls
of this form most of which rely on AUTOLOAD to load the class and
method(s) on demand (this keeps the memory footprint down).
Here is an example that demonstrates the problem, note the lines to be
uncommented near the bottom:
#!/usr/local/bin/perl -w
package UNIVERSAL;
sub AUTOLOAD {
print "UNIVERSAL::AUTOLOAD=$AUTOLOAD\n" unless $AUTOLOAD =~
/DESTROY/;
if ($AUTOLOAD =~ /^(.*)::(.*)$/ ) {
my ($class,$sub) = ($1,$2);
if ($sub eq 'new') {
my $self = {xxx => 1};
bless $self, $class;
return $self;
} else {
return "$AUTOLOAD **results**";
}
}
}
#text forms of AUTOLOAD
package main;
my $n;
#this succeeeds but gets message:
# Use of inherited AUTOLOAD for non-method foo::anysub()
# is deprecated...
my $xx=foo::anysub();
print ref $xx ? "object class:$xx\n" : "sub:$xx\n";
#this succeeeds and returns an object of class foo
my $xx=foo->new();
print ref $xx ? "object class:$xx\n" : "sub:$xx\n";
# *** IF THE LINES FURTHER ON ARE COMMENTED THIS FAILS WITH MESSAGE:
# Can't locate object method "new" via package "bar" (perhaps
# you forgot to load "bar"?)...
# *** OTHERWISE IT WORKS WHY?? ***
my $xx=bar->new();
print ref $xx ? "object class:$xx\n" : "sub:$xx\n";
# *** IF YOU UNCOMMENT THESE 2 LINES THE ABOVE WORKS ***
#my $xx=bar::new();
#print ref $xx ? "object class:$xx\n" : "sub:$xx\n";
print "Finished\n";
--
John Clutterbuck <john.clutterbuck@siemens.com>
------------------------------
Date: Fri, 11 Oct 2002 15:04:55 +0200
From: "Jan Klaverstijn" <jan@klaverstijn.nl>
Subject: Re: Problem with require() versus in-line code
Message-Id: <3da6cc91$0$11216$1b62eedf@news.euronet.nl>
"Koos Pol" <koos_pol@NO.nl.JUNK.compuware.MAIL.com> schreef in bericht
news:newscache$5n6t3h$hec$1@news.emea.compuware.com...
> Jan Klaverstijn wrote (Thursday 10 October 2002 17:38):
>
> > The solution with a package and :: is obscure to me: if I declare
"package
> > conf;" in file_a.pl that I require in file_b.pl and refer to my data
> > structure as
> > for my $where ( @{ $conf::fetchmailrc{servers} } )
{
> > it still won' work.
> >
> > I must admit I had hoped it would be easier. More like #include as in C.
>
> Well, actually it is that simple. The problem you are facing is different:
> you want to get to variable data while it is outscoped and thus not
> visible. But actually that is a Good Thing, because now you are sure that
> what you do in your little black box remains save from prying eyes!
>
It is a good thing to have. Scoping is a wonderfull thing. Wanting something
like header files is another. One does not exclude the use for the other.
And I was hoping for the header file approach.
I have not yet made clear what my exact intentions are. I use the wonderful
fetchmail program to handle my ISP mailboxes. I have a cleanup script on
Perl that discards emails when they exceed a certain age. fetchmail cannot
do that. For that I need my fetchmail configuration. fetchmail could dump
its configuration in Python format and I transformed that into Perl. So what
I get is a datastructure initialized with all fetchmail configuration
options. That IMHO called for a header file approach.
> > So I hope my package reference above is broken and easily fixed.
> > Otherwisre I'll have to revert to another advice, from Koos Pol, to
> > implement a sub in the package and call that. This would bridge the
> > namespaces but makes the file generation process more complicated.
>
> Why? You can pass to your function variable data, file names, filehandles,
> what ever you want. If I run
>
> do_something($on_this_data, $and_export_to_this_file);
>
So that's what I did. I now generate a package with a sub.
package conf;
sub config {
return ( ... my hash goes here ...)
}
I call that sub with
require "conf.pl";
my %fetchmailrc = &conf::getConfig();
This works like a dream so I settle with this. I have to move
> ...well, it doesn't get easier. Now you moved some
> low-level-technical-routine-noone-is-really-interested-in to it's own
file.
> I don't see this difference in difficulty between writing this routine in
> the current file or in a different file and "require"ing it. Better, both
> routines are probably textuallly equal. And that concludes to that it
> perhaps should have been a routine in the first place!
>
There is no real difficulty. I am just a very lazy programmer. That makes
for optimal code.
I will probably not implement a module. I'd consider an OOP implementation
but I currently have no urgent need.
> HTH!
It does!
I'd like to thank both Domizio and Koos (landgenoot?) for their efforts. It
was a learning experience. The internet would not be the same without guys
like you.
Jan.
> --
> KP
>
------------------------------
Date: Fri, 11 Oct 2002 06:53:33 -0500
From: Reuben Logsdon <rlogsdon@io.com>
Subject: problems with PDF files and -T switch
Message-Id: <Pine.LNX.4.44.0210110635140.32614-100000@hagbard.io.com>
Hello,
I find that 90% of my PDF files (which are all binary files) are returning
true on Perl's -T is-text-file switch.
I understand that this is because -T only checks the first block, and
PDF's tend to be mixed text/binary with all the binary towards the end, so
I know this isn't a bug in Perl exactly. But...
What I need is to reliably detect whether any given file is text or binary
because my file upload system needs to do line-ending conversion on text
files. Currently it's corrupting my users' PDF files by doing conversion
on them. Does anyone have their own enhanced -T replacement which will
work better? Are there other files types that are known to behave this
way?
My default approach will be to continue to use -T but override it for the
PDF extension. It feels like a dirty and weak solution to a serious
problem. I may also default the text-conversion to "off" and provide a
file-by-file control, but still at some level I want to have an
auto-detect routine. I've done a lot of searches but I can't find any
discussion of this problem.
Regards,
Reuben Logsdon
------------------------------
Date: Fri, 11 Oct 2002 14:16:52 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: problems with PDF files and -T switch
Message-Id: <Pine.LNX.4.40.0210111359560.2114-100000@lxplus071.cern.ch>
On Oct 11, Reuben Logsdon inscribed on the eternal scroll:
> What I need is to reliably detect whether any given file is text or binary
I don't think that's a well-formed problem. In general, a bag of
bytes can always be handled as binary, although it might by chance
also make sense as text. Any test based only on its content is bound
to be heuristic, and thus cannot be truly "reliable".
Or to put it another way, show me your algorithm and I can pretty
certainly produce an example to defeat it.
> because my file upload system needs to do line-ending conversion on text
> files.
I'd suggest reconsidering the design. Take a look at
multipart/form-data, in which each of the uploaded parts can be
accompanied by a Content-type specification. On the basis of that
specification the sender can tell you whether it's text
(text/something) or not (probably application/something).
If the sender can't define what they're uploading to this degree
then it would be hard to take them seriously as a source of input...
Remember, even bog-standard FTP requires the submitter to choose
between A (text) or I (binary) or whatever other upload format that
FTP supports (yeah, I used to do mainframes where Ebcdic was also
supported). Or at least to provide usable information to a UI which
guesses for them. You have a better chance of the content type being
known on the system which is providing the data, than on some other
system where your server is running and accepting that data.
> Currently it's corrupting my users' PDF files by doing conversion
> on them.
If you don't know reliably what you're dealing with, then the only
safe move is to store the content as binary. Then, look for some
other way of mapping that into text if that turns out to be what is
wanted.
Any other procedure risks loss of data in a proportion of cases: you
can reduce that proportion, but you cannot eliminate it.
You could of course look at "man file" (assuming a unix-ish system).
> Are there other files types that are known to behave this
> way?
postscript ?
And another question: if it turns out to be text, which character
coding are you going to assume? If uploading text from a Mac to Unix
are you remembering to transcode between macRoman and iso-8859-1, or
whichever pair of codings is relevant to your locale?
good luck
--
Gratuitous bigotry, pedantry and sophistry has no place on the Web.
That's what Usenet is for. - Andy Dingley
------------------------------
Date: Fri, 11 Oct 2002 08:44:09 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: problems with PDF files and -T switch
Message-Id: <slrnaqdld9.2co.tadmc@magna.augustmail.com>
Reuben Logsdon <rlogsdon@io.com> wrote:
> I find that 90% of my PDF files (which are all binary files) are returning
> true on Perl's -T is-text-file switch.
> What I need is to reliably detect whether any given file is text or binary
If you can change the question, then the answer might get easier. :-)
Would this be good enough?
What I need is to reliably detect whether any given file is
PDF or not.
> My default approach will be to continue to use -T but override it for the
> PDF extension.
A search for "PDF" on CPAN finds PDF::Parse::IsaPDF()
which sound promising...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 11 Oct 2002 10:26:58 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Returning hashrefs
Message-Id: <ao691i$j8up8$2@fu-berlin.de>
Sean McAfee <mcafee@artemis.transmeta.com> wrote:
> Wow, this is tricky! I think I've got it figured out, though.
[explanation]
there's another thing:
try
my $y = baz();
my $z = baz2();
instead of
my ($y, $z) = (baz(), baz2());
and add:
print Dumper $y;
print Dumper $z;
(i left out the "&"'s, they are useless and confusing here)
scalar context for baz2() does return the right result:
{
'1' => 2,
'3' => 4
}
scalar context for baz() returns "1/8".
regards, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 11 Oct 2002 11:56:36 GMT
From: getwebwise@aol.com (GetWebWise)
Subject: Sendmail
Message-Id: <20021011075636.25234.00000715@mb-fm.aol.com>
Hi
Being a newbie, I am not sure if this is the correct place to post this enquiry
but here goes any way.
I am using sendmail and I would like to insert a link to a word document in
oder that the email recipent may download it.
Coding the web page the link would look like this
<A HREF="myresume.doc">Download my resume"</A>
How do I get the same result in the email using Perl?
Many Thanks
Ian
------------------------------
Date: Fri, 11 Oct 2002 13:17:29 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Sendmail
Message-Id: <3da6cef3.9595767@news.cis.dfn.de>
On 11 Oct 2002 11:56:36 GMT, getwebwise@aol.com (GetWebWise)
wrote:
>Being a newbie, I am not sure if this is the correct place to post
> this enquirybut here goes any way.
Definitely not.
>I am using sendmail and I would like to insert a link to a word
>document in oder that the email recipent may download it.
>
>Coding the web page the link would look like this
> <A HREF="myresume.doc">Download my resume"</A>
>
>How do I get the same result in the email using Perl?
Use the print function, Luke.
As in:
print '<A HREF="myresume.doc">Download my resume"</A>';
Although you might need more of an URL than that if
you want it to work properly.
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Fri, 11 Oct 2002 08:55:18 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Should -i eat my files?
Message-Id: <slrnaqdm26.2co.tadmc@magna.augustmail.com>
Johannes Fürnkranz <johannes.fuernkranz@t-online.de> wrote:
> John W. Krahn wrote:
>>
>> perldoc perldiag
>> [snip]
>> Can't do inplace edit without backup
>> (F) You're on a system such as MS-DOS that gets con
>> fused if you try reading from a deleted (but still
>> opened) file. You have to say `-i.bak', or some such.
>
> Thanks, I did not know that.
>
> But even if I had known it, I would have assumed that -i simply does not
> work on Windows systems. This gives absolutely no indication that it
> will delete my files! Shouldn't there at least a big warning somewhere,
> or better, an implementation that refuses to use -i on an OS where it can't?
So you want to retract that "but real men don't need backups" now?
:-)
When you decided to use "bare" -i, you knew you were entering
dangerous territory. You went anyway.
But a warning wouldn't hurt either.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 11 Oct 2002 16:43:08 +0300
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: Synchronizing my perl processes
Message-Id: <ao6kh5$jtlli$1@ID-33095.news.dfncis.de>
D. Alvarado wrote:
> Hi, I have a perl script, call it, "mine.pl", which I'm running on our
> Solaris servers. Basically I don't want more than one instance
> running at a time, and if the script is attempted to run through the
> command
>
>> perl mine.pl
>
> while another instance of mine.pl is running, I'd like the second
> instance to sleep until the first instance is finished running, and
> then continue running (This is called a join, right?).
>
One of the ways to do it:
1. Open a file at some known location (lockfile).
2. Acquire a lock (write/exclusive) on the file.
At this point your process will be blocked
if the other copy holds the lock.
3. When got the lock - do your job. You may wish to write
the pid of your process to the lockfile.
You do not have to release the lock manually - when your
process terminates the file will be closed and the lock
released automagically.
Look at example below (untested).
Ilja.
#!/usr/bin/perl -w
use strict;
use Fcntl qw(O_RDWR O_CREAT LOCK_EX);
my $pidfile = '/var/run/my_program.pid';
sysopen PF, $pidfile, O_RDWR|O_CREAT or die "cannot sysopen $pidfile: $!\n";
flock PF, LOCK_EX or die "cannot flock $pidfile: $!\n";
# got the lock, write our pid
truncate PF, 0 or die "cannot truncate $pidfile: $!\n";
select((select(PF), $| = 1)[0]);
print PF "$$\n" or die "cannot print to $pidfile: $!\n";
print "Got the lock, time to work...\n";
sleep 60; # or do domething more usefull
# that's all
------------------------------
Date: Fri, 11 Oct 2002 12:05:00 +0200
From: David Bouman <david.bouman@xo.nl>
Subject: Re: The Perl Journal needs help
Message-Id: <3DA6A24C.5384A6AF@xo.nl>
neanti wrote:
> Please help saving a great publication!
>
> <http://www.tpj.com/> 'Time is running short and we need your help if
> The Perl Journal is to get another chance at being the real deal. As
> of a couple of minutes ago, we only have 881 subscriptions and the
> deadline is fast approaching. Please subscribe now. It only costs 3
> cents per day to get the best Perl coverage anywhere.'" They need
> 3,000 subscribers to move forward.
1600 it says now. Make that 1600 and 1.
--
David.
------------------------------
Date: Fri, 11 Oct 2002 13:16:27 +0200
From: "Brutus" <pef@trasig.noXX>
Subject: ultiple "my" declaration
Message-Id: <ao6bvc$suj$1@oslo-nntp.eunet.no>
Just as we used to say: int a, b, c;
I'd like to go: my $a, $b, $c;
but no. perl requires explicit package names in the declarations, fine.
But isn't it a bit awkward having to write
my $a; my $b; my $this; my $that; ???
comment from anyone ?
Brit
------------------------------
Date: Fri, 11 Oct 2002 11:25:17 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: ultiple "my" declaration
Message-Id: <3da6b4cf.2903645@news.cis.dfn.de>
On Fri, 11 Oct 2002 13:16:27 +0200, "Brutus"
<pef@trasig.noXX> wrote:
>Just as we used to say: int a, b, c;
>
>I'd like to go: my $a, $b, $c;
>
>but no. perl requires explicit package names in the declarations, fine.
>
>But isn't it a bit awkward having to write
>my $a; my $b; my $this; my $that; ???
my ($a,$b,$c);
On the other hand, these days I usually declare my
variables as they are initialised, thus I seldom need
to declare many at once.
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Fri, 11 Oct 2002 07:26:19 -0400
From: David Martin <DJMartin@DynaComp-Solutions.com>
Subject: Re: ultiple "my" declaration
Message-Id: <MPG.18107f69682928df9896f6@news.mindspring.com>
In article <ao6bvc$suj$1@oslo-nntp.eunet.no>, pef@trasig.noXX says...
> I'd like to go: my $a, $b, $c;
my ($a,$b,$c);
David Martin
DynaComp Solutions
http://DynaComp-Solutions.com
------------------------------
Date: Fri, 11 Oct 2002 13:36:58 +0200
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: ultiple "my" declaration
Message-Id: <newscache$mxet3h$0gc$1@news.emea.compuware.com>
Brutus wrote (Friday 11 October 2002 13:16):
> Just as we used to say: int a, b, c;
>
> I'd like to go: my $a, $b, $c;
>
> but no. perl requires explicit package names in the declarations, fine.
>
> But isn't it a bit awkward having to write
> my $a; my $b; my $this; my $that; ???
>
> comment from anyone ?
>
> Brit
You may want to read 'perldoc -f my' one more time...
How about:
my ($a, $b, $this, $that);
HTH
--
KP
------------------------------
Date: Fri, 11 Oct 2002 08:59:31 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: ultiple "my" declaration
Message-Id: <slrnaqdma3.2co.tadmc@magna.augustmail.com>
Brutus <pef@trasig.noXX> wrote:
> I'd like to go: my $a, $b, $c;
perldoc -f my
will tell you how to fix that.
> but no. perl requires explicit package names in the declarations, fine.
^^^^^^^^ ^^^^^^^^^^^^^
Not in the declarations for lexical (my) variables.
lexical variables do not *have* any package name.
--
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 3954
***************************************