[25480] in Perl-Users-Digest
Perl-Users Digest, Issue: 7725 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 2 06:05:41 2005
Date: Wed, 2 Feb 2005 03:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 2 Feb 2005 Volume: 10 Number: 7725
Today's topics:
Re: compacting '..' path segments using File::Spec <vek@station02.ohout.pharmapartners.nl>
Compile perl code/files via STDIN (mseele)
Re: Compile perl code/files via STDIN <spamtrap@dot-app.org>
Re: converting vertical text to horizontal text <do-not-use@invalid.net>
Date Manipulation: Week_Number back to Date <wls@wwco.com>
Re: Date Manipulation: Week_Number back to Date <mgjv@tradingpost.com.au>
Re: Date Manipulation: Week_Number back to Date <noreply@gunnar.cc>
Re: Date Manipulation: Week_Number back to Date <comdog@panix.com>
Emacs modules for Perl programming (Jari Aalto+mail.perl)
Hashtable of arrays <apokrif1@yahoo.com>
Re: Hashtable of arrays <mikevh2.1@netzero.com>
Re: How bad is $'? (Was: "Get substring of line") bik.mido@gmail.com
Re: Invisible cache for LWP / Mechanize? <jakob.fix@gmail.com>
Re: Invisible cache for LWP / Mechanize? <jakob.fix@gmail.com>
Re: perl and web development <tintin@invalid.invalid>
Re: perl quick date convert (replace z with h, spam protection)
Re: saving file attachment from mbox ? <jurgenex@hotmail.com>
stop extra lines from printing <pauliecat@sasktel.net>
Re: stop extra lines from printing <richard@zync.co.uk>
To parse files.. clearguy02@yahoo.com
Re: To parse files.. <rasto@gmx.at>
what does each file do in webmin? <lie_huo@hotmail.com>
Re: x-www-form-urlencoded <nospam@bigpond.com>
Re: x-www-form-urlencoded <no@email.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 02 Feb 2005 08:28:12 GMT
From: Villy Kruse <vek@station02.ohout.pharmapartners.nl>
Subject: Re: compacting '..' path segments using File::Spec
Message-Id: <slrnd013or.3ed.vek@station02.ohout.pharmapartners.nl>
On 1 Feb 2005 10:36:59 -0800,
ofer@netapt.com <ofer@netapt.com> wrote:
> I'll ignore the two morons and reply to the one who seems to have
> understood what I'm trying to accomplish.
>
> By the description of canonpath ('a logical cleanup of a path'), and
> your example, it would seem to be what I'm looking for. I threw it in
> to my test script... and it didn't change the path at all. It still
> returns /foo/bar/../somefile instead of /foo/somefile.
>
Some news message in this group said quite a while ago that eliminating
/../ sequences might not be the reight thing to do if symbolic links
are involved. If /foo/bar is a symbolic link then .. whont get you back
to /foo but the parent directory to the directory the symbolic link is
pointing to. That is, unless you interpret the .. logically as is often
done by the shell.
Villy
------------------------------
Date: 1 Feb 2005 23:48:57 -0800
From: mseele@gmail.com (mseele)
Subject: Compile perl code/files via STDIN
Message-Id: <554147f0.0502012348.75e961b9@posting.google.com>
yes you're write, i want to provide my code by typing
directly from the command line, rather than executing a pre-existing
file containing perl code.
but i don't want to end the perl process after compilation of one
file, i want to use the -c option, get the result and want to put new
perl code into the perl process a later time. how can i do this? is it
actually possible?
------------------------------
Date: Wed, 02 Feb 2005 03:21:53 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Compile perl code/files via STDIN
Message-Id: <HI2dnfcBj88-EJ3fRVn-sw@adelphia.com>
mseele wrote:
> yes you're write
*Who* is right? A little context please - quote the relevant parts of the
message you're replying to, and post your reply as a *reply*, not as the
start of a new thread.
, i want to provide my code by typing
> directly from the command line, rather than executing a pre-existing
> file containing perl code.
Why? I'm serious - Take a step back, and tell us what problem you're trying
to solve using this approach.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 02 Feb 2005 09:56:19 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: converting vertical text to horizontal text
Message-Id: <yzdfz0f5oi4.fsf@invalid.net>
"Larry" <larry_wallet@yahoo.com> writes:
> I tried writing a script that would collect all of the letters together
> and feed them into a web based anagram solver. Maybe the anagram site
> I chose was no good, but it couldn't solve it. You might need a
> customized anagram solver that can make intelligent choices based on
> the partial order of the text.
Dear google-poster, do try to find a configuration when posting through
google that keeps the context information of what you're replying to.
Subject and reference numbers are there, but not the most immediate thing
people want to see, namely the actual text you are referring to (including
its author).
------------------------------
Date: 1 Feb 2005 18:20:51 -0800
From: "wls" <wls@wwco.com>
Subject: Date Manipulation: Week_Number back to Date
Message-Id: <1107310851.924385.119230@g14g2000cwa.googlegroups.com>
I've found a number of functions and expressions for taking dates and
converting them to a week number.
Interestingly enough, I need to go in the reverse direction.
( $day, $mon, $year ) = ReverseTheProcess( 2007, 7 ); # Week 7 of 2007
is 4-Feb-2007
Is there such a beast, or does someone have a clever way to calculate
it?
Thanks,
-wls@wwco.com
------------------------------
Date: 02 Feb 2005 03:03:25 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Date Manipulation: Week_Number back to Date
Message-Id: <slrnd00go3.cjd.mgjv@verbruggen.comdyn.com.au>
On 1 Feb 2005 18:20:51 -0800,
wls <wls@wwco.com> wrote:
> I've found a number of functions and expressions for taking dates and
> converting them to a week number.
>
> Interestingly enough, I need to go in the reverse direction.
>
> ( $day, $mon, $year ) = ReverseTheProcess( 2007, 7 ); # Week 7 of 2007
> is 4-Feb-2007
Week 7 of 2007 is a range of seven days. 4 Feb 2007 is a Sunday, not a
week.
> Is there such a beast, or does someone have a clever way to calculate
> it?
The Date::Calc module has a method
Monday_of_Week
($year,$month,$day) = Monday_of_Week($week,$year);
which probably is what you want. If you need the Sunday instead of the
Monday, also use Add_Delta_Days() or one of those.
http://search.cpan.org/
Martien
--
|
Martien Verbruggen | Failure is not an option. It comes bundled
| with your Microsoft product.
|
------------------------------
Date: Wed, 02 Feb 2005 05:59:07 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Date Manipulation: Week_Number back to Date
Message-Id: <36b5d6F4pe4b3U1@individual.net>
Martien Verbruggen wrote:
> wls wrote:
>> I've found a number of functions and expressions for taking dates
>> and converting them to a week number.
>>
>> Interestingly enough, I need to go in the reverse direction.
<snip>
> The Date::Calc module has a method
>
> Monday_of_Week
> ($year,$month,$day) = Monday_of_Week($week,$year);
That's probably the best way. Still, out of curiosity I gave it a try
using my favorite module Time::Local. ;-)
sub MondayOfWeek {
my ($year, $week) = @_;
require Time::Local;
import Time::Local 'timegm';
my $firstday = ( gmtime timegm(0,0,0,1,0,$year-1900) )[6];
my ($d, $m, $y) = ( gmtime( ($week-1)*604800 +
timegm(0,0,0,(1+(8-$firstday)%7),0,$year-1900) ) )[3..5];
sprintf '%d-%02d-%02d', $y+1900, $m+1, $d
}
print MondayOfWeek( 2007, 7 ), "\n";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 02 Feb 2005 00:48:29 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: Date Manipulation: Week_Number back to Date
Message-Id: <020220050048295499%comdog@panix.com>
In article <36b5d6F4pe4b3U1@individual.net>, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
> Martien Verbruggen wrote:
> > The Date::Calc module has a method
> >
> > Monday_of_Week
> > ($year,$month,$day) = Monday_of_Week($week,$year);
>
> That's probably the best way. Still, out of curiosity I gave it a try
> using my favorite module Time::Local. ;-)
>
> sub MondayOfWeek {
> }
This sort of thing makes me think there should be a big
book of Date Recipes in <Foo>, just like we have Numerical
Recipes in <Foo>. :)
--
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com
------------------------------
Date: 02 Feb 2005 05:23:00 GMT
From: <jari.aalto <AT> poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1107321737@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto A T poboxes com
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Unix Windows port (for Unix die-hards):
install http://www.cygwin.com/ which includes native Emacs 21.x.
and XEmacs port
o Pure Native Windows port
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/ => Emacs resource page
Emacs Perl Modules
Cperl -- Perl programming mode
http://www.cpan.org/modules/by-authors/id/ILYAZ/cperl-mode/
http://math.berkeley.edu/~ilya/software/emacs/
by Ilya Zakharevich
CPerl is major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
standard in newest Emacs.
TinyPerl -- Perl related utilities
http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Grep through all Perl manpages (.pod)
o Follow POD references e.g. [perlre] to next pod with RETURN
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o Update `$VERSION' variable with YYYY.MMDD on save.
o Load source code into Emacs, like Devel::DProf.pm
o Prepare script (version numbering) and Upload it to PAUSE
o Generate autoload STUBS (Devel::SelfStubber) for you
Perl Module (.pm)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in Tiny Tools Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up dattabases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to to do the search, You can adjust
recursive grep options, set search case sensitivity, add user grep
options etc.
You can find latest `igrep.el' module at
<http://groups.google.com/groups?group=gnu.emacs.sources> The
maintainer is Jefin Rodgers <kevinr <AT> ihs.com>.
TinyCompile -- To Browse grep results in Emacs *compile* buffer
TinyCompile is a minor mode for *compile* buffer from where
you can collapse unwanted lines or shorten file URLs:
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: 02 Feb 2005 05:35:41 +0100
From: Apokrif <apokrif1@yahoo.com>
Subject: Hashtable of arrays
Message-Id: <80zmyn1sv6.fsf@apokrif.xyz>
I've got a lexicon file which contains lines such as "chaise,
fauteuil=seat, chair" (one or several [more or less] synonymous French
words on the left, and their translation on the right). I'm trying to
build a hashtable that uses the French word as a key, and returns a
list containing English translations:
chaise=>(chair,seat)
fauteuil=>(chair,seat)
I wrote::
%translations=();
while (<FILE>){
chomp;
($left, $right)=split(/=/,$_);
@words_on_the_left=split (/, /, $left);
@words_on_the_right=split (/, /, $right);
for $word (@words_on_the_left){
if (!defined($translations{$word}))
{
$translations{$word}=@words_on_the_right;
}else{
$translations{$word}=($translations{$word}, @words_on_the_right);
}
print $translations{$word};
}
}
This doesn't work: instead of displaying English translations, the
script prints a list of numbers (which lets me think that the lists
are interpreted in a scalar context). I tried to adapt examples I
found on the Web and I replaced in several places "$" with "@" or with
"@{$", and I also tried to replace
"$translations{$word}=($translations{$word}, @words_on_the_right);"
with "$translations{$word}=($translations{$word},
\@words_on_the_right);"; sometimes the program prints what looks like
pointers, but I don't get the results I expected.
------------------------------
Date: 1 Feb 2005 22:20:12 -0800
From: "mike" <mikevh2.1@netzero.com>
Subject: Re: Hashtable of arrays
Message-Id: <1107325212.500702.84740@c13g2000cwb.googlegroups.com>
0. You should declare your variables with my and use strict.
1. Hash values cannot be arrays. They may be references to arrays.
2. Use exists() to tell whether a hash key exists, not defined().
3. I don't think you want to add a definition to an already existing
key if that definition already exists.
I think the following does what you want:
|#!perl
|use strict;
|use warnings;
|use Data::Dumper;
|
|my %translations;
|while (<DATA>){
| chomp;
| my ($left, $right) = split /\s*=\s*/;
| my @words_left = split(/,\s*/, $left);
| my @words_right = split(/,\s*/, $right);
| for my $word (@words_left) {
| unless (exists($translations{$word})) {
| $translations{$word} = [ @words_right ];
| } else {
| for my $nw (@words_right) {
| unless (grep /^$nw$/, @{$translations{$word}}) {
| push(@{$translations{$word}}, $nw);
| }
| }
| }
| }
|}
|my $d = Data::Dumper->new([\%translations], [qw(*translations)]);
|print $d->Dump;
|
|__DATA__
|chaise,fauteuil=seat, chair
|fauteuil=ottoman,seat
Output:
|%translations = (
| 'chaise' => [
| 'seat',
| 'chair'
| ],
| 'fauteuil' => [
| 'seat',
| 'chair',
| 'ottoman'
| ]
| );
See
perldoc -f my
perldoc strict
perldoc perlreftut
perldoc perldsc
perldoc perlref
perldoc perllol
HTH
------------------------------
Date: 2 Feb 2005 01:10:52 -0800
From: bik.mido@gmail.com
Subject: Re: How bad is $'? (Was: "Get substring of line")
Message-Id: <1107335452.133366.250010@g14g2000cwa.googlegroups.com>
jl_post@hotmail.com wrote:
> (Okay, so I know that Michele will probably not read this post, but
> I've decided to answer his reply anyway, for the benefit of anybody
who
> might be interested in this thread.)
Well, every now and again I give a peek into google-groups...
> > >my $prefix = q!$a = $' if "a" =~ m/a/;!;
> > >my $line = '$a = 1 if "abc=xyz" =~ m/=/;';
> >
> > Why are you (running under strict and) using as a
> > generic variable the predefined global variable $a?
[snip]
> > I mean, this post of yours has some flavour of a tutorial: so why
> > exposing to potential newbies something we usually warn them
against?
>
> Good question. I'll give three answers:
>
> First, I didn't mean this post to be a tutorial. I meant it to be
easy
I didn't claim it is. I said it "has some flavour of", which reflects
the impression I get out of it.
> Second, I don't think there's much harm in teaching potential newbies
> about $', $&, and $`, as long as the obligatory warning is given (as
it
> almost always is).
I was not talking about this, but about using $a and $b as general
purpose variables.
> And third, if we're not supposed to expose potential newbies to these
> match variables, then I have to point out that Randal Schwartz and
Tom
Ditto as above!
> > Also, indeed lines of code benchmarked as strings are
> > (string-)eval()ed which means that they are parsed and
> > executed as stand-alone perl programs, but (as of the
> > docs => see!) _in the lexical context_ of the current
> > program, which means that the interpreter they're executed
> > with is not a total stranger to the current one.
>
> I'm not quite sure if I understand you perfectly here. It sounds
like
> you're saying that even if I use $' once in my code, it "spoils" all
> the regular expressions (even the ones that have no need for $'). If
This is what's written in the docs.
> this is what you mean, I have to point out that I'm eval()ing the
"bad"
> code (the code with $') AFTER the "good" code is eval()ed. In other
Well, but then I _think_ (although I'm not really _sure_) that even if
you're running the code through a string eval() the interpreters run to
execute the code _are_ still affected by the side effect of using $',
or, as you say, 'taintedness'.
Why do I think so? Because, still as of the docs and as already hinted
above eval()ed strings are parsed and run in _the lexical context_ of
the current program. But let's check for ourselves; consider this
script:
| #!/usr/bin/perl
|
| use strict;
| use warnings;
| use Benchmark qw/:all :hireswallclock/;
|
| # 'aaaa' =~ /a/ and $';
|
| timethis -30, q{ 'aaaa' =~ /a/ }, 'all';
|
| __END__
Running it I get
| all: 36.9275 wallclock secs (35.77 usr + 0.14 sys = 35.91 CPU)
| @ 1343370.29/s (n=48240427)
whereas if I uncomment the commented line I get
| all: 32.1861 wallclock secs (30.69 usr + 0.18 sys = 30.87 CPU)
| @ 417959.18/s (n=12902400)
(Output slightly edited for clarity in both cases, but then please try
this yourself.)
I think that the figures are significative.
> words, the "good" code finishes executing before the Perl interpreter
> ever gets a chance to eval() the "bad" code and discover that the $'
> variable is being used at all. As a result, the $' taint in the
"bad"
> code shouldn't get a chance to spoil the "good" code.
Are you sure? What about the test above then?!?
HTH,
Michele
------------------------------
Date: 2 Feb 2005 00:25:38 -0800
From: "jfix" <jakob.fix@gmail.com>
Subject: Re: Invisible cache for LWP / Mechanize?
Message-Id: <1107332738.836262.11510@z14g2000cwz.googlegroups.com>
It only seems that LWP is the problem's source. So if LWP gives me
outdated data, then SimpleLinkExtor won't be able to fix that.
Thanks anyway,
Jakob.
------------------------------
Date: 2 Feb 2005 00:33:42 -0800
From: "jfix" <jakob.fix@gmail.com>
Subject: Re: Invisible cache for LWP / Mechanize?
Message-Id: <1107333222.049940.136700@l41g2000cwc.googlegroups.com>
Just thinking: I am behind a proxy/firewall. It must be this proxy
that caches previous results. Will have to look int ways to force the
proxy to not return cached responses, but fresh data.
Any ideas?
--
cheers,
Jakob.
------------------------------
Date: Wed, 2 Feb 2005 19:58:31 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: perl and web development
Message-Id: <36bbt9F4uv7g8U1@individual.net>
"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote in message
news:Pine.LNX.4.61.0502011540220.4966@ppepc56.ph.gla.ac.uk...
> On Tue, 1 Feb 2005, Jürgen Exner wrote:
>
>> Is a screw driver or a hammer faster in most instances?
>
> Prompts the question which one stands for Perl, and which for PHP
Neither.
Perl is the Swiss army knife and PHP is the mallet.
------------------------------
Date: Wed, 2 Feb 2005 11:19:15 +0100
From: "D. Marxsen" <detlef.marxsen@tdds-gmbz.de (replace z with h, spam protection)>
Subject: Re: perl quick date convert
Message-Id: <ctq9f7$l6o$1@domitilla.aioe.org>
<asdfq213rr23we@yahoo.com> schrieb im Newsbeitrag
news:1107301944.546808.87910@o13g2000cwo.googlegroups.com...
> Hi
>
> Whats the smoothest way of converting the date string "2004-10-10
> 12:14:23" to "Tue, 10 Oct 2004 12:14:23"?
I use Date::Calc
Dunno if it is the smoothest way - but it very simple to use and it has a
huge set of functions.
Cheers,
Detlef.
--
D. Marxsen, TD&DS GmbH
detlef.marxsen@tdds-gmbz.de (replace z with h, spam protection)
------------------------------
Date: Wed, 02 Feb 2005 04:41:03 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: saving file attachment from mbox ?
Message-Id: <zRYLd.1174$uc.159@trnddc02>
Mad Scientist Jr wrote:
> evidently you perl guys aren't using the same kind of newsreader.
What the f*** are you talking about? Please provide some context.
> i was not aware of that issue, as i use google,
Google is not a newsreader but an archive with a web interface.
> which displays the whole thread
Yeah, sure, for an archive that is a good thing to have.
For a newsreader it would be very userunfriendly.
jue
------------------------------
Date: 2 Feb 2005 01:49:31 -0800
From: "pauliecat@sasktel.net" <pauliecat@sasktel.net>
Subject: stop extra lines from printing
Message-Id: <1107337771.913742.299260@z14g2000cwz.googlegroups.com>
having all sorts of problems extracting the data. The file I am
extracting on is library catalog records. For instance sometimes I get
the subject printing in the wrong record, or blank lines between each
subject (some records have more than one subject field)
eg: Author Joe Blow
Title Fishing in a coal mine
SUBJ Fishing
SUBJ Coal mines
I'll get results like this
Author Joe Blow
Title Fishing in a coal mine
SUBJ Fishing
SUBJ Coal mines
I'd like to be able for instance keep things together and then have a
blank line between the last element of the first record and a space
between the start of the next record: Here is the script
my $title;
my $author;
my $call;
my $subj;
for my $line (@lines)
{
$line =~ /TITLE/ and $title = $line;
$line =~ /AUTHOR/ and $author = $line;
$line =~ /CALL/ and $call = $line;
$line =~ /SUBJ/ and $subj = $line;
#$line =~ /did not find/ and print $title,$line,"\n";
$line =~ /PUB/ and print $title,$author,$call,$subj,$line,"\n";
}
------------------------------
Date: Wed, 02 Feb 2005 09:51:53 +0000
From: Richard Gration <richard@zync.co.uk>
Subject: Re: stop extra lines from printing
Message-Id: <pan.2005.02.02.09.51.53.273615@zync.co.uk>
On Wed, 02 Feb 2005 01:49:31 -0800, pauliecat@sasktel.net wrote:
> having all sorts of problems extracting the data. The file I am
> extracting on is library catalog records. For instance sometimes I get
> the subject printing in the wrong record, or blank lines between each
> subject (some records have more than one subject field)
It looks to me like you aren't removing the newline from the end of your
input lines. See extra line in code below.
<SNIP>
> my $title;
> my $author;
> my $call;
> my $subj;
>
> for my $line (@lines)
> {
chomp($line); # <-- Will remove newline from end of $line, if present
> $line =~ /TITLE/ and $title = $line;
> $line =~ /AUTHOR/ and $author = $line; $line =~ /CALL/ and $call =
> $line;
> $line =~ /SUBJ/ and $subj = $line;
> #$line =~ /did not find/ and print $title,$line,"\n"; $line =~ /PUB/ and
> print $title,$author,$call,$subj,$line,"\n";
>
> }
------------------------------
Date: 1 Feb 2005 22:47:14 -0800
From: clearguy02@yahoo.com
Subject: To parse files..
Message-Id: <1107326834.838727.179060@c13g2000cwb.googlegroups.com>
Hi perl experts:
I have the following issue.
I have a list of 5 Windows machines and I have a command
"C:\uptime.exe" to see if any of these five machines are not alive. If
a machine is not alive, it gives an output message "UPTIME was unable
to connect to host: \\Machine". For instance, the three machines,
JOHN-2K, ANNA5 and Test machines are not alive and you would see the
first line as ""UPTIME was unable to connect to host: \\JOHN-2K".
My code:
============================
open (OUT1, ">D:\\test5.txt") || die " Can not write to the file: $!";
foreach (<DATA>)
{
print OUT1 "c:\\uptime $_ ";
}
close (OUT1);
open (IN2, "D:\\test5.txt") || die " Can not open the file: $!";
@IN = <IN2>;
open (OUT2, ">D:\\test6.txt") || die " Can not write to the file: $!";
foreach (@IN)
{
next unless /^\s*UPTIME was unable to connect to host/;
print ???????
}
__DATA__
BOB-2K
JOHN-2K
SMITH-2
ANNA5
Test
============================
I know that I need to use "system" command instead of the "print"
command in the script. But I don't know how to run the system command
and print the output to a file handle at the same time.
Finally, I need to get only the following lines in output file,
D:\\test6.txt:
======================================
UPTIME was unable to connect the followng hosts:
1. JOHN-2K
2. ANNA2
3. Test
======================================
How can I modify my script to get this output?
Thanks in advance,
Rider.
------------------------------
Date: Wed, 02 Feb 2005 10:40:39 +0100
From: Rasto Levrinc <rasto@gmx.at>
Subject: Re: To parse files..
Message-Id: <42009f4d$0$11352$3b214f66@tunews.univie.ac.at>
clearguy02@yahoo.com wrote:
> print OUT1 "c:\\uptime $_ ";
> I know that I need to use "system" command instead of the "print"
> command in the script. But I don't know how to run the system command
> and print the output to a file handle at the same time.
Use backticks like this: print OUT1 `c:\\uptime $_ `;
You can also do it all in one loop.
--
Rasto Levrinc
http://sourceforge.net/projects/rlocate/
------------------------------
Date: Wed, 02 Feb 2005 04:17:47 -0500
From: "Roll" <lie_huo@hotmail.com>
Subject: what does each file do in webmin?
Message-Id: <99fc75d527466dde3074f77ab86a1c0c@localhost.talkaboutprogramming.com>
hi can anyone here tell me what does each file in the dhcp folder of the
webmin do ??
------------------------------
Date: Wed, 02 Feb 2005 13:45:52 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: x-www-form-urlencoded
Message-Id: <36b0nhF50199vU1@individual.net>
Dan Jacobson wrote:
> What can I use to turn text into x-www-form-urlencoded text?
> I.e., I want to do something like
> $ perl -nwe 'print x-www-form-urlencoded($_)'
> if you know what I mean.
Not really.
Maybe you were looking for:
http://theoryx5.uwinnipeg.ca/CPAN/perl/pod/perlfaq9/How_do_I_decode_or_create_those_-encodin.html
gtoomey
------------------------------
Date: Wed, 02 Feb 2005 07:19:31 +0000
From: Brian Wakem <no@email.com>
Subject: Re: x-www-form-urlencoded
Message-Id: <36bd83F4vssthU1@individual.net>
Dan Jacobson wrote:
> What can I use to turn text into x-www-form-urlencoded text?
> I.e., I want to do something like
> $ perl -nwe 'print x-www-form-urlencoded($_)' if you know what I mean.
use URI::Escape;
print uri_escape($_);
--
Brian Wakem
------------------------------
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 7725
***************************************