[11599] in Perl-Users-Digest
Perl-Users Digest, Issue: 5199 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 22 13:07:25 1999
Date: Mon, 22 Mar 99 10:01:28 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 22 Mar 1999 Volume: 8 Number: 5199
Today's topics:
Re: removing ASCII chars < 32 <wk@rayleigh.ecs.soton.ac.uk>
Re: removing ASCII chars < 32 <Allan@due.net>
Re: removing ASCII chars < 32 (Abigail)
Re: removing ASCII chars < 32 (Abigail)
Re: Sending to multiple recipients via Sendmail <hurtta+usenet @ozone.FMI.FI>
Re: Sending/recieving scsi commands - DLT on Solaris (Peter Corlett)
Re: Substitution question <upsetter@ziplink.net>
UserAgent or Cookies or user failing? gmichel@my-dejanews.com
Weird $_ behavior <upsetter@ziplink.net>
Re: What isn't getting reset? <cassell@mail.cor.epa.gov>
Re: What isn't getting reset? <aqumsieh@matrox.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 22 Mar 1999 16:13:13 +0000
From: Wayne Keenan <wk@rayleigh.ecs.soton.ac.uk>
Subject: Re: removing ASCII chars < 32
Message-Id: <36F66C18.691F6278@rayleigh.ecs.soton.ac.uk>
Thanks, but..
Bart Lateur wrote:
>
> $string =~ s/\000-\037//d;
>
{
print "Sending: ".$line;
chomp($line);
$port->send($line."\r\n");
$text=$port->clear();
$text =~ s/\000-\037//d ; #strip buf of chars < 32
}
I get this error:
Bareword found where operator expected at main.pl line 62, near
"s/\000-\037//d"
Unquoted string "d" may clash with future reserved word at main.pl line
62.
syntax error at main.pl line 62, near "s/\000-\037//d "
Execution of main.pl aborted due to compilation errors.
Another point:
I could do 3 substitutions (to avoid the \t & \n) but is there a shorter
way?
>
>
> $string =~ tr/\t\n / /s;
>
Thanks again.
------------------------------
Date: Mon, 22 Mar 1999 12:46:18 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: removing ASCII chars < 32
Message-Id: <7d5v85$7i4$1@camel18.mindspring.com>
Bart Lateur wrote in message <36f71c73.7597555@news.skynet.be>...
:Wayne Keenan wrote:
:>how can one remove ASCII chars < 32 in strings?
:If $string is the scalar holding your string:
: $string =~ s/\000-\037//d;
:The numbers are in octal, base 8, so "\037" is the character with Ascii
:code 31.
Hmm, shouldn't the above use a char class? And shouldn't that be a g
instead of a d?
$string =~ s/[\000-\037]//g;
AmD
--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
I'd rather have a free bottle in front of me than a prefrontal lobotomy.
- Fred Allen
------------------------------
Date: 22 Mar 1999 17:52:34 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: removing ASCII chars < 32
Message-Id: <7d6012$2p7$1@client2.news.psi.net>
Wayne Keenan (wk@rayleigh.ecs.soton.ac.uk) wrote on MMXXIX September
MCMXCIII in <URL:news:36F61637.4AB81ACD@rayleigh.ecs.soton.ac.uk>:
\\ how can one remove ASCII chars < 32 in strings?
With a regex.
Abigail
--
perl -weprint\<\<EOT\; -eJust -eanother -ePerl -eHacker -eEOT
------------------------------
Date: 22 Mar 1999 17:55:32 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: removing ASCII chars < 32
Message-Id: <7d606k$2p7$2@client2.news.psi.net>
Bart Lateur (bart.lateur@skynet.be) wrote on MMXXIX September MCMXCIII in
<URL:news:36f71c73.7597555@news.skynet.be>:
"" Wayne Keenan wrote:
""
"" >how can one remove ASCII chars < 32 in strings?
""
"" If $string is the scalar holding your string:
""
"" $string =~ s/\000-\037//d;
Did you try that? It would remove the 3 character string "\x00", "-", "\x1F",
if it wasn't for the unknown /d flag that gives a parsing error.
"" The numbers are in octal, base 8, so "\037" is the character with Ascii
"" code 31.
""
"" Note that this will delete newlmines and tabs as well. Maybe you'd like
"" these to be converted to (single) spaces instead. Then, do the next
"" before the above:
""
"" $string =~ tr/\t\n / /s;
That doesn't do what you think it does. There's no interpolation with tr.
$string =~ s/[\x00-\x1F]+//g;
Abigail
--
perl -we '$_ = q ;4a75737420616e6f74686572205065726c204861636b65720as;;
for (s;s;s;s;s;s;s;s;s;s;s;s)
{s;(..)s?;qq qprint chr 0x$1 and \161 ssq;excess;}'
------------------------------
Date: 22 Mar 1999 17:12:20 +0200
From: "Kari E. Hurtta" <hurtta+usenet @ozone.FMI.FI>
Subject: Re: Sending to multiple recipients via Sendmail
Message-Id: <dp4sndftij.fsf@oxygen.fmi.fi>
[Retry -- first posting seems to have failed.]
In article <36F56D67.4B68F5AA@spots.ab.ca>
Martin Foster <mfoster@spots.ab.ca> writes
in comp.lang.perl.misc,comp.mail.sendmail:
>> ehlo IPADDRESS
Yoo mean:
ehlo [IPADDRESS]
where IPADDRESS is sender's ip-address.
> mail from: whoever@who.care.com
You mean:
mail from:<whoever@who.care.com>
> rcpt to: first@person.com
You mean:
rcpt to:<first@person.com>
> rcpt tp: second@person.com
You mean:
rcpt to:<second@person.com>
> ..
> ..
> data
> Marry had a little Lamb.
You mean:
data
From: <whoever@who.care.com>
To: My mailing list:;
> .
> quit
>
> And the list of these the message has gone two is not directly given
> out since, you will also have to create the headers yourself (just rip
> them off another E-Mail client and use that as a blueprint). It
> actually works quite well once you figure out the protocol and
> discover that though you really don't care what SMTP outputs, you need
> to input it before sending out the next command.
>
> Martin Foster
> mfoster@spots.ab.ca
/ Kari Hurtta
------------------------------
Date: 22 Mar 99 10:00:47 GMT
From: peterc@verrine.demon.co.uk (Peter Corlett)
Subject: Re: Sending/recieving scsi commands - DLT on Solaris
Message-Id: <36f614cf.0@news1lo.highwayone.net>
bobn <bobn@interaccess.com> wrote:
> I'm trying to retrieve information from a DLT drive (not the tape
> in the drive, but registers/pages inside the controller) connected
> to a Sun Ultra-2 box running Solaris 2.5.1. These pages have
> information regarding compression ratios, error logs, etc.
[...]
> I've actually tried read/write to /dev/rmt/0 - the write of an
> inquiry frame doesn't faile, but attempting to read the response
> does.
> I've tried severla searches of CPAN and found nothing. Any help in
> understanding how to do this. either from the Unix or Perl point of
> view, would be highly appreciated.
I've no experience of adminning Solaris, but I'm fairly sure you're
trying to open the wrong device. Under Linux, you access /dev/st?,
(the equivalent of /dev/rmt/0) to read/write data to a SCSI tape, and
there are a number of ioctls to set parameters. AFAIAA, there is no
way of sending SCSI commands to this device.
To send raw SCSI commands, you most likely need the equivalent of
Linux's /dev/sg? devices, which allow you to send raw SCSI commands
to the drive. If Solaris doesn't do this (and if so, why not?) then
you'll have to start kernel hacking.
I had a similar problem where I wanted to do some "special" stuff
with a CD-ROM drive (okay, I wanted to rip CDDA audio to code MP3s
from) and needed to send vendor specific commands. A scour of CPAN
didn't help me, so I hacked at it, and many kernel panics later, I
have something that works for me. I'll send you a copy for reference,
but is very unlikely it will work directly.
How would I go about putting it in CPAN?
[Could direct replies be CC'd to me - I do read the group, but this
newsfeed is patchy.]
--
Peter Corlett, Many-hatted BOFH, tw2.com Limited.
use Standard::Disclaimer qw/Not my employer's opinion/;
------------------------------
Date: Mon, 22 Mar 1999 16:40:14 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: Substitution question
Message-Id: <OnuJ2.361$Yk5.74999@news.shore.net>
Tad McClellan <tadmc@metronet.com> wrote:
: Scratchie (upsetter@ziplink.net) wrote:
: : Also, the backslash is unneccesary before the @ in a regex.
: The backslash is necessary before the @ in double quotish strings.
: Regex patterns are double quotish.
: The backslash is necessary.
My mistake. It works if you're just looking for an '@' sign (/@/) but
requires a backslash otherwise.
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Mon, 22 Mar 1999 14:52:50 GMT
From: gmichel@my-dejanews.com
Subject: UserAgent or Cookies or user failing?
Message-Id: <7d5lft$kud$1@nnrp1.dejanews.com>
Hi,
I am trying to mimic my Netscape browser and retrieve documents from a site
that is username/password protected and uses cookies.
I seem to be pretty close, but for some reason $ua fails to give the server
what it wants. According to LWP::Debug, I get a
LWP::Protocol::http::request: need more header data
line and the file never arrives. The cookie exchange seems to be okay.
Below is a "sanitized" version of the code. If someone would like to suggest
some changes that might avoid the problem I'd appreciate it.
Thanks,
George Michel
(Please email me at gmichel@siteriggers.com if more info is needed.)
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Request::Common qw(POST);
use LWP::Debug qw(+ +conns +debug);
open(OUT,">outputfile");
$netfile="/root/.netscape/cookies";
$ua = LWP::UserAgent->new;
$ua->agent("Mozilla/4.0");
$ua->cookie_jar(HTTP::Cookies::Netscape->new(File => $file, AutoSave =>
1,ignore_discard=>1));
$req= POST 'http://www.address.com',
[URI=>'/path/to/file',
Tag=>'/',
User=>'<EDITED>',
Password=>'<EDITED>',
];
$cont = $ua->request($req,"tmp");
print $cont->content;
print OUT $cont->content;
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 22 Mar 1999 17:12:52 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Weird $_ behavior
Message-Id: <oSuJ2.369$Yk5.75577@news.shore.net>
I've come across something weird, and I'm wondering if it's documented
anywhere.
Assume I've previously set $DATA_DIR to some valid directory.
This bit of code should find all the sub-directories and parse
the contents of each "index.txt" file (key/value tab separated)
into a hash of hashes keyed by subdirectory.
foreach (`ls $DATA_DIR`) {
print;
chomp;
$file = "$DATA_DIR/$_/index.txt";
if (-e $file) {
print "This is \$_: ", $_, "\n";
# hard code values for testing purposes
# $cont{$_} = { &File2Hash2($file) };
$cont{$_} = { 'key1' => 'value1', 'key2' => 'value2' };
print "This is \$_: ", $_, "\n";
}
}
# print out the results
foreach my $key (sort keys %cont) {
print "$key:\n";
foreach (sort keys %{$cont{$key}}) {
print "\t$_: $cont{$key}{$_}\n";
}
}
When I run the above code, I get the expected results:
Program commencing
00001
This is $_: 00001
This is $_: 00001
00002
This is $_: 00002
This is $_: 00002
00003
This is $_: 00003
This is $_: 00003
00001:
key1: value1
key2: value2
00002:
key1: value1
key2: value2
00003:
key1: value1
key2: value2
However, when I try to use the "real" data, something strange happens. The
subroutine to convert a file to a hash is pretty straightforward:
sub File2Hash2 {
my ($input) = shift @_;
open (FILE,$input) or die ("Could not open $input: $!");
my %hash;
my ($key, $value);
while (<FILE>) {
chomp;
# assumes two-field layout
($key,$value) = split(/\t/);
$hash{$key} = $value;
}
close FILE;
return %hash;
}
Yet when I change the original code to
$cont{$_} = { &File2Hash2($file) };
# $cont{$_} = { 'key1' => 'value1', 'key2' => 'value2' };
It seems to wipe out the contents of $_:
Program commencing
00001
This is $_: 00001
This is $_:
00002
This is $_: 00002
This is $_:
00003
This is $_: 00003
This is $_:
:
BARFOO: This is something else
CONTESTDESC: This is not the third contest
FOOBAR: tHIS IS fOOBAR!
If I replace $_ with some other variable, it works fine:
foreach my $directory (`ls $DATA_DIR`) {
print $directory;
chomp $directory;
$file = "$DATA_DIR/$directory/index.txt";
if (-e $file) {
print "This is \$directory: ", $directory, "\n";
$cont{$directory} = { &File2Hash2($file) };
# $cont{$directory} = { 'key1' => 'value1', 'key2' =>
'value2' };
print "This is \$directory: ", $directory, "\n";
}
}
Program commencing
00001
This is $directory: 00001
This is $directory: 00001
00002
This is $directory: 00002
This is $directory: 00002
00003
This is $directory: 00003
This is $directory: 00003
00001:
CONTESTDESC: This is the first contest
00002:
CONTESTDESC: This is the second contest
00003:
BARFOO: This is something else
CONTESTDESC: This is not the third contest
FOOBAR: tHIS IS fOOBAR!
orion (art)% perl -v
This is perl, version 5.004_04 built for sun4-solaris
Am I missing something obvious here? Thanks in advance.
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Mon, 22 Mar 1999 09:08:17 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: What isn't getting reset?
Message-Id: <36F67901.1DA38CAA@mail.cor.epa.gov>
Barron Michael Wegman wrote:
> Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote:
>
> : What version of Perl are you using?
> :
> : This is likely a bug in earlier versions of Perl which has now been
> : fixed.
>
> I'm using a fairly recent version, 5.004_04 built for alpha-dec_osf.
>
> Sorry, I meant to mention this in my question, but I forgot.
While this is *fairly* recent, it is not up-to-date.. as I have had
people tell me too. :-) If feasible, upgrade to the current version.
5.005 is extremely stable, and fixes a few 5.004 bugs which might be
biting you. Plus, perldoc gets better!
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 22 Mar 1999 10:35:04 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: What isn't getting reset?
Message-Id: <x3yzp557d1z.fsf@tigre.matrox.com>
Barry Wegman <bwegman@HiWAAY.net> writes:
>
> $s = "This is a test of the American Broadcasting Service."
> @matches = ($s =~ /([tT]\S{1,})/); ## NOTE: Not done globally!
> print "Matched: ", join(", ", @matches), "\n";
> @matches = ($s =~ /([tT]\S{1,})/g);
> print "Matched: ", join(", ", @matches), "\n";
> @matches = ($s =~ /([tT]\S{1,})/g);
> print "Matched: ", join(", ", @matches), "\n";
>
> Forgive my newbie question, but the above code produces the
> following output, which I don't understand. Can someone please
> explain it to me? (Please E-mail me a copy of any responses.)
>
> Matched: This
> Matched: test, the, ting
> Matched: This, test, the, ting
>
> Clearly, something is not getting reset between the first and
> second matches. Otherwise, the second and third matches would
> be the same. Their code is identical. The first match is NOT
> global. What isn't being reset? And how can I reset it?
What version of Perl are you using?
On my Perl (This is perl, version 5.004_04 built for sun4-solaris), I
get the following results:
Matched: This
Matched: This, test, the, ting
Matched: This, test, the, ting
which is clearly what you expect.
HTH,
Ala
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5199
**************************************