[25472] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7717 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 31 18:05:45 2005

Date: Mon, 31 Jan 2005 15:05:13 -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           Mon, 31 Jan 2005     Volume: 10 Number: 7717

Today's topics:
        [perl-python] find & replace strings for all files in a <xah@xahlee.org>
    Re: capturing perl forks patrisha@alumni.washington.edu
    Re: capturing perl forks <1usa@llenroc.ude.invalid>
    Re: Installing DBI module on Windows XP <ebohlman@omsdev.com>
        Int. Conf. on Systems Engineering'05 - August 16-18, 20 <avinash.ramani@gmail.com>
        International Conference on Computational Intelligence  <avinash.ramani@gmail.com>
        International Conference on Computational Intelligence  <avinash.ramani@gmail.com>
        Perl "pipe" command, cant print binary to handle <perlrules@darklaser.com>
    Re: Perl equivalent for Unix ps. <someone@example.com>
    Re: Perl equivalent for Unix ps. <vilain@spamcop.net>
    Re: Perl equivalent for Unix ps. <abigail@abigail.nl>
    Re: Perl loops should use break, not last <cwilbur@mithril.chromatico.net>
    Re: Perl newbie -  getting "system()" to return <tadmc@augustmail.com>
    Re: Q: quoting string without escapes <steve@holdenweb.com>
    Re: recursive function and hashe <jgibson@mail.arc.nasa.gov>
    Re: recursive function and hashe <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 31 Jan 2005 12:30:10 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: [perl-python] find & replace strings for all files in a dir
Message-Id: <1107203410.397877.309750@c13g2000cwb.googlegroups.com>

suppose you want to do find & replace of string of all files in a
directory.
here's the code:

=A9# -*- coding: utf-8 -*-
=A9# Python
=A9
=A9import os,sys
=A9
=A9mydir=3D '/Users/t/web'
=A9
=A9findStr=3D'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN">'
=A9repStr=3D'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">'
=A9
=A9def replaceStringInFile(findStr,repStr,filePath):
=A9    "replaces all findStr by repStr in file filePath"
=A9    tempName=3DfilePath+'~~~'
=A9    input =3D open(filePath)
=A9    output =3D open(tempName,'w')
=A9
=A9    for s in input:
=A9        output.write(s.replace(findStr,repStr))
=A9    output.close()
=A9    input.close()
=A9    os.rename(tempName,filePath)
=A9    print filePath
=A9
=A9def myfun(dummy, dirr, filess):
=A9     for child in filess:
=A9         if '.html' =3D=3D os.path.splitext(child)[1] and
=A9os.path.isfile(dirr+'/'+child):
=A9             replaceStringInFile(findStr,repStr,dirr+'/'+child)
=A9os.path.walk(mydir, myfun, 3)


note that files will be overwritten.
be sure to backup the folder before you run it.

try to edit the code to suite your needs.

previous tips can be found at:
http://xahlee.org/perl-python/python.html

---------------------------------------
the following is a Perl version i wrote few years ago.
Note: if regex is turned on, correctness is not guranteed.
it is very difficult if not impossible in Perl to move regex pattern
around and preserve their meanings.


#!/usr/local/bin/perl

=3Dpod

Description:
This script does find and replace on a given foler recursively.

Features:
* multiple Find and Replace string pairs can be given.
* The find/replace strings can be set to regex or literal.
* Files can be filtered according to file name suffix matching or other

criterions.
* Backup copies of original files will be made at a user specified
folder that preserves all folder structures of original folder.
* A report will be generated that indicates which files has been
changed, how many changes, and total number of files changed.
* files will retain their own/group/permissions settings.

usage:
1=2E edit the parts under the section '#-- arguments --'.
2=2E edit the subroutine fileFilterQ to set which file will be checked or

skipped.

to do:
* in the report, print the strings that are changed, possibly with
surrounding lines.
* allow just find without replace.
* add the GNU syntax for unix command prompt.
* Report if backup directory exists already, or provide toggle to
overwrite, or some other smarties.

Date created: 2000/02
Author: Xah

=3Dcut

#-- modules --

use strict;
use File::Find;
use File::Path;
use File::Copy;
use Data::Dumper;

#-- arguments --

# the folder to be search on.
my $folderPath =3D q[/Users/t/web/UnixResource_dir];

# this is the backup folder path.
my $backupFolderPath =3D q[/Users/t/xxxb];

my %findReplaceH =3D (
q[<pre><a href=3D"freebooks.html">back to Unix
Pestilence</a><pre>]=3D>q[<pre>? Back to <a href=3D"freebooks.html">Unix
Pestilence</a></pre>],
);

# $useRegexQ has values 1 or 0. If 1, inteprets the pairs in
%findReplaceH
# to be regex.
my $useRegexQ =3D 0;

# in bytes. larger files will be skipped
my $fileSizeLimit =3D 500 * 1000;


#-- globals --

$folderPath =3D~ s[/$][]; # e.g. '/home/joe/public_html'
$backupFolderPath =3D~ s[/$][]; # e.g. '/tmp/joe_back';

$folderPath =3D~ m[/(\w+)$];
my $previousDir =3D $`;   # e.g. '/home/joe'
my $lastDir =3D $1;       # e.g. 'public_html'
my $backupRoot =3D $backupFolderPath . '/' . $1; # e.g.
'/tmp/joe_back/public_html'

my $refLargeFiles =3D [];
my $totalFileChangedCount =3D 0;

#-- subroutines --

# fileFilterQ($fullFilePath) return true if file is desired.
sub fileFilterQ ($) {
my $fileName =3D $_[0];

if ((-s $fileName) > $fileSizeLimit) {
push (@$refLargeFiles, $fileName);
return 0;
};
if ($fileName =3D~ m{\.html$}) {
print "processing: $fileName\n";
return 1;};

##        if (-d $fileName) {return 0;}; # directory
##        if (not (-T $fileName)) {return 0;}; # not text file

return 0;
};

# go through each file, accumulate a hash.
sub processFile {
my $currentFile =3D $File::Find::name; # full path spect
my $currentDir =3D $File::Find::dir;
my $currentFileName =3D $_;

if (not fileFilterQ($currentFile)) {
return 1;
}

# open file. Read in the whole file.
if (not(open FILE, "<$currentFile")) {die("Error opening file:
$!");};
my $wholeFileString;
{local $/ =3D undef; $wholeFileString =3D <FILE>;};
if (not(close(FILE))) {die("Error closing file: $!");};

# do the replacement.
my $replaceCount =3D 0;

foreach my $key1 (keys %findReplaceH) {
my $pattern =3D ($useRegexQ ? $key1 : quotemeta($key1));
$replaceCount =3D $replaceCount + ($wholeFileString =3D~
s/$pattern/$findReplaceH{$key1}/g);
};

if ($replaceCount > 0) { # replacement has happened
$totalFileChangedCount++;
# do backup
# make a directory in the backup path, make a backup
copy.
my $pathAdd =3D $currentDir; $pathAdd =3D~
s[$folderPath][];
mkpath("$backupRoot/$pathAdd", 0, 0777);
copy($currentFile,
"$backupRoot/$pathAdd/$currentFileName") or
die "error: file copying file failed on
$currentFile\n$!";

# write to the original
# get the file mode.
my ($mode, $uid, $gid) =3D (stat($currentFile))[2,4,5];

# write out a new file.
if (not(open OUTFILE, ">$currentFile")) {die("Error
opening file: $!");};
print OUTFILE $wholeFileString;
if (not(close(OUTFILE))) {die("Error closing file:
$!");};

# set the file mode.
chmod($mode, $currentFile);
chown($uid, $gid, $currentFile);

print "-----^$*%$@#-------------------------------\n";
print "$replaceCount replacements made at\n";
print "$currentFile\n";
}

};


#-- main body --

find(\&processFile, $folderPath);

print "--------------------------------------------\n\n\n";
print "Total of $totalFileChangedCount files changed.\n";

if (scalar @$refLargeFiles > 0) {
print "The following large files are skipped:\n";
print Dumper($refLargeFiles);
}


__END__
Xah
 xah@xahlee.org
 http://xahlee.org/PageTwo_dir/more.html



------------------------------

Date: 31 Jan 2005 11:31:09 -0800
From: patrisha@alumni.washington.edu
Subject: Re: capturing perl forks
Message-Id: <1107199869.521019.254470@z14g2000cwz.googlegroups.com>

That does help, thankyou, but I was hoping for a more generic method of
overriding the functionality. I have been using Perl "magic" to capture
access to variables and for some C code
I have running in the background. It would be nice to be able to do
this in the background
through "magic". 

Thanks again
Patricia



------------------------------

Date: 31 Jan 2005 20:53:30 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: capturing perl forks
Message-Id: <Xns95EFA1A8AFEBCasu1cornelledu@132.236.56.8>

patrisha@alumni.washington.edu wrote in news:1107199869.521019.254470
@z14g2000cwz.googlegroups.com:

> That does help, 

What does help? Please provide some context when replying. The fact that 
you and I know what we are talking about at this point in time does not 
mean others also do.

> thankyou, but I was hoping for a more generic method of
> overriding the functionality. I have been using Perl "magic" to capture
> access to variables and for some C code
> I have running in the background. It would be nice to be able to do
> this in the background through "magic". 

I do not know what you mean by "magic". If you want to modify the behavior 
of a built-in, you'll have to do some work. 

Sinan.


------------------------------

Date: 31 Jan 2005 22:23:52 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: Installing DBI module on Windows XP
Message-Id: <Xns95EFA810AD1F9ebohlmanomsdevcom@130.133.1.4>

"Manzoorul  Hassan" <manzoorul.hassan@gmail.com> wrote in 
news:1107188575.820339.125930@f14g2000cwb.googlegroups.com:

> I would like to install the DBI module on my Windows XP system. I am
> really looking for a module that will let me connect to a MSDE (or MS
> SQL) DB.

You'll want to get DBD::ODBC along with DBI.


------------------------------

Date: 31 Jan 2005 11:40:47 -0800
From: "avinash" <avinash.ramani@gmail.com>
Subject: Int. Conf. on Systems Engineering'05 - August 16-18, 2005
Message-Id: <1107200447.057191.297140@z14g2000cwz.googlegroups.com>

International Conference on Computational Intelligence and
Multimedia Applications, August 16-18, 2005
University of Nevada, Las Vegas, USA
(www.iccima.org)
F I R S T    C A L L      F O R     P A P E R S


The International Conference on Computational Intelligence and
Multimedia Applications will be held at the University of Nevada, Las
Vegas, USA on August 16-18, 2005. The conference will provide an
international forum for discussion on issues in the areas of
Computational Intelligence and Multimedia for scientists, engineers,
researchers and practitioners. ICCIMA05 is organized jointly with
International Conference on Systems Engineering (ICSE'05:
www.icseng.info) and the registered participants of ICCIMA05 will be
able to attend ICSEng05.

The conference will include sessions on theory, implementation and
applications, as well as the non-technical areas of challenges in
education and technology transfer to industry. There will be both oral
and poster sessions.  Accepted full papers will be included in the
proceedings  to be published by IEEE CS Press. Selected papers will be
published in "International Journal on Computational Intelligence and
Applications" published by World Scientific Publishing Company Press.
Several well-known keynote speakers will address the conference.

Conference Topics Include (but not limited to):
Artificial Intelligence
Artificial Neural Networks
Pattern Recognition
Fuzzy Systems
Genetic Algorithms
Hybrid Systems
Intelligent Control
Intelligent Databases
Knowledge-based Engineering
Learning Algorithms
Memory, Storage and Retrieval
Multimedia Systems
Formal Models for Multimedia
Interactive Multimedia
Multimedia and Virtual Reality
Multimedia and Telecommunications
Multimedia Information Retrieval
Multimedia and Security
Multimedia Hardware
Multimedia and Algorithms

Special Sessions, Pre-Conference Workshops and Tutorial:

Proposals for special sessions, pre-conference workshops and tutorials
relevant to the conference topics are invited. The deadline for
submitting the proposal is Feb 15, 2005.

Special Poster Session:

ICCIMA'05 will include a special poster session devoted to recent work
and work-in-progress. Abstracts are solicited for this session (2 page
limit) in camera ready form, and may be submitted up to 30 days before
the conference date. They will not be refereed and will not be
included in the proceedings, but will be distributed to attendees upon
arrival. Students are especially encouraged to submit abstracts for
this session.

Invited Sessions

Keynote speakers (key industrialists, chief research  scientists and
leading academics) will be addressing the main issues of the
conference.

Important Dates:

Submission of papers received latest on:  March 10, 2005

Submission of Papers

Papers in English reporting original and unpublished research results
and experience are solicited. Electronic submission of papers via
www.iccima.org. Visit the web page for more information.

Page Limits

Papers for refereeing should be double-spaced and must include an
abstract of 100-150 words with up to six keywords.
Selected papers will have a limit of 6 pages in the proceedings to be
published by IEEE.

Evaluation Process

All submissions will be refereed based on the following criteria by
two reviewers with appropriate background.

originality
significance
contribution to the area of research
technical quality
relevance to ICCIMA 2005 topics
clarity of presentation

Referees report will be provided to all authors.

Check List

Prospective authors should check that the following items are attached
and guidelines followed while submitting the papers for refereeing
purpose.

* The paper and its title page should not contain the name(s) of
the author(s), or their affiliation
* The paper should have attached a covering page containing
the following information

-title of the paper
-author name(s), title, affiliation, mail and e-mail
addresses, phone
and fax numbers
-Conference topic area
-up to six keywords

* The name, e-mail, phone, fax and postal address of the contact
person should be attached to the submission.

Contact Information:

ICCIMA' 05 Secretariat
Department of Electrical and Computer Engineering
University of Nevada, Las Vegas
4505 Maryland Parkway, Box 454026
Las Vegas, NV 89154-4026
USA

Phone:  +1 702 895 4184
Fax:      +1 702 895 1115
email:    secretary@iccima.org
URL:      http://www.iccima.org/



------------------------------

Date: 31 Jan 2005 11:40:19 -0800
From: "avinash" <avinash.ramani@gmail.com>
Subject: International Conference on Computational Intelligence and Multimedia Applications 2005
Message-Id: <1107200419.215104.9990@f14g2000cwb.googlegroups.com>

International Conference on Computational Intelligence and
Multimedia Applications, August 16-18, 2005
University of Nevada, Las Vegas, USA
(www.iccima.org)
F I R S T    C A L L      F O R     P A P E R S


The International Conference on Computational Intelligence and
Multimedia Applications will be held at the University of Nevada, Las
Vegas, USA on August 16-18, 2005. The conference will provide an
international forum for discussion on issues in the areas of
Computational Intelligence and Multimedia for scientists, engineers,
researchers and practitioners. ICCIMA05 is organized jointly with
International Conference on Systems Engineering (ICSE'05:
www.icseng.info) and the registered participants of ICCIMA05 will be
able to attend ICSEng05.

The conference will include sessions on theory, implementation and
applications, as well as the non-technical areas of challenges in
education and technology transfer to industry. There will be both oral
and poster sessions.  Accepted full papers will be included in the
proceedings  to be published by IEEE CS Press. Selected papers will be
published in "International Journal on Computational Intelligence and
Applications" published by World Scientific Publishing Company Press.
Several well-known keynote speakers will address the conference.

Conference Topics Include (but not limited to):
Artificial Intelligence
Artificial Neural Networks
Pattern Recognition
Fuzzy Systems
Genetic Algorithms
Hybrid Systems
Intelligent Control
Intelligent Databases
Knowledge-based Engineering
Learning Algorithms
Memory, Storage and Retrieval
Multimedia Systems
Formal Models for Multimedia
Interactive Multimedia
Multimedia and Virtual Reality
Multimedia and Telecommunications
Multimedia Information Retrieval
Multimedia and Security
Multimedia Hardware
Multimedia and Algorithms

Special Sessions, Pre-Conference Workshops and Tutorial:

Proposals for special sessions, pre-conference workshops and tutorials
relevant to the conference topics are invited. The deadline for
submitting the proposal is Feb 15, 2005.

Special Poster Session:

ICCIMA'05 will include a special poster session devoted to recent work
and work-in-progress. Abstracts are solicited for this session (2 page
limit) in camera ready form, and may be submitted up to 30 days before
the conference date. They will not be refereed and will not be
included in the proceedings, but will be distributed to attendees upon
arrival. Students are especially encouraged to submit abstracts for
this session.

Invited Sessions

Keynote speakers (key industrialists, chief research  scientists and
leading academics) will be addressing the main issues of the
conference.

Important Dates:

Submission of papers received latest on:  March 10, 2005

Submission of Papers

Papers in English reporting original and unpublished research results
and experience are solicited. Electronic submission of papers via
www.iccima.org. Visit the web page for more information.

Page Limits

Papers for refereeing should be double-spaced and must include an
abstract of 100-150 words with up to six keywords.
Selected papers will have a limit of 6 pages in the proceedings to be
published by IEEE.

Evaluation Process

All submissions will be refereed based on the following criteria by
two reviewers with appropriate background.

originality
significance
contribution to the area of research
technical quality
relevance to ICCIMA 2005 topics
clarity of presentation

Referees report will be provided to all authors.

Check List

Prospective authors should check that the following items are attached
and guidelines followed while submitting the papers for refereeing
purpose.

* The paper and its title page should not contain the name(s) of
the author(s), or their affiliation
* The paper should have attached a covering page containing
the following information

-title of the paper
-author name(s), title, affiliation, mail and e-mail
addresses, phone
and fax numbers
-Conference topic area
-up to six keywords

* The name, e-mail, phone, fax and postal address of the contact
person should be attached to the submission.

Contact Information:

ICCIMA' 05 Secretariat
Department of Electrical and Computer Engineering
University of Nevada, Las Vegas
4505 Maryland Parkway, Box 454026
Las Vegas, NV 89154-4026
USA

Phone:  +1 702 895 4184
Fax:      +1 702 895 1115
email:    secretary@iccima.org
URL:      http://www.iccima.org/



------------------------------

Date: 31 Jan 2005 11:41:05 -0800
From: "avinash" <avinash.ramani@gmail.com>
Subject: International Conference on Computational Intelligence and Multimedia Applications 2005
Message-Id: <1107200465.518808.13360@f14g2000cwb.googlegroups.com>

International Conference on Computational Intelligence and
Multimedia Applications, August 16-18, 2005
University of Nevada, Las Vegas, USA
(www.iccima.org)
F I R S T    C A L L      F O R     P A P E R S


The International Conference on Computational Intelligence and
Multimedia Applications will be held at the University of Nevada, Las
Vegas, USA on August 16-18, 2005. The conference will provide an
international forum for discussion on issues in the areas of
Computational Intelligence and Multimedia for scientists, engineers,
researchers and practitioners. ICCIMA05 is organized jointly with
International Conference on Systems Engineering (ICSE'05:
www.icseng.info) and the registered participants of ICCIMA05 will be
able to attend ICSEng05.

The conference will include sessions on theory, implementation and
applications, as well as the non-technical areas of challenges in
education and technology transfer to industry. There will be both oral
and poster sessions.  Accepted full papers will be included in the
proceedings  to be published by IEEE CS Press. Selected papers will be
published in "International Journal on Computational Intelligence and
Applications" published by World Scientific Publishing Company Press.
Several well-known keynote speakers will address the conference.

Conference Topics Include (but not limited to):
Artificial Intelligence
Artificial Neural Networks
Pattern Recognition
Fuzzy Systems
Genetic Algorithms
Hybrid Systems
Intelligent Control
Intelligent Databases
Knowledge-based Engineering
Learning Algorithms
Memory, Storage and Retrieval
Multimedia Systems
Formal Models for Multimedia
Interactive Multimedia
Multimedia and Virtual Reality
Multimedia and Telecommunications
Multimedia Information Retrieval
Multimedia and Security
Multimedia Hardware
Multimedia and Algorithms

Special Sessions, Pre-Conference Workshops and Tutorial:

Proposals for special sessions, pre-conference workshops and tutorials
relevant to the conference topics are invited. The deadline for
submitting the proposal is Feb 15, 2005.

Special Poster Session:

ICCIMA'05 will include a special poster session devoted to recent work
and work-in-progress. Abstracts are solicited for this session (2 page
limit) in camera ready form, and may be submitted up to 30 days before
the conference date. They will not be refereed and will not be
included in the proceedings, but will be distributed to attendees upon
arrival. Students are especially encouraged to submit abstracts for
this session.

Invited Sessions

Keynote speakers (key industrialists, chief research  scientists and
leading academics) will be addressing the main issues of the
conference.

Important Dates:

Submission of papers received latest on:  March 10, 2005

Submission of Papers

Papers in English reporting original and unpublished research results
and experience are solicited. Electronic submission of papers via
www.iccima.org. Visit the web page for more information.

Page Limits

Papers for refereeing should be double-spaced and must include an
abstract of 100-150 words with up to six keywords.
Selected papers will have a limit of 6 pages in the proceedings to be
published by IEEE.

Evaluation Process

All submissions will be refereed based on the following criteria by
two reviewers with appropriate background.

originality
significance
contribution to the area of research
technical quality
relevance to ICCIMA 2005 topics
clarity of presentation

Referees report will be provided to all authors.

Check List

Prospective authors should check that the following items are attached
and guidelines followed while submitting the papers for refereeing
purpose.

* The paper and its title page should not contain the name(s) of
the author(s), or their affiliation
* The paper should have attached a covering page containing
the following information

-title of the paper
-author name(s), title, affiliation, mail and e-mail
addresses, phone
and fax numbers
-Conference topic area
-up to six keywords

* The name, e-mail, phone, fax and postal address of the contact
person should be attached to the submission.

Contact Information:

ICCIMA' 05 Secretariat
Department of Electrical and Computer Engineering
University of Nevada, Las Vegas
4505 Maryland Parkway, Box 454026
Las Vegas, NV 89154-4026
USA

Phone:  +1 702 895 4184
Fax:      +1 702 895 1115
email:    secretary@iccima.org
URL:      http://www.iccima.org/



------------------------------

Date: 31 Jan 2005 11:05:23 -0800
From: "David" <perlrules@darklaser.com>
Subject: Perl "pipe" command, cant print binary to handle
Message-Id: <1107198323.896908.183970@f14g2000cwb.googlegroups.com>

Hey all, I'm working on a script that reads from STDIN.  This will
be "use"ed by other scripts.  These other scripts may be useing other
lib's which want to read from STDIN as well.
So I've written this code which works great for re-populating STDIN
except for when I try to print binary to the handle.

my $input = join('', <STDIN>);
close(STDIN);
pipe(STDIN, TOSTDIN);
print TOSTDIN $input;
close(TOSTDIN);

in the senario where I get an image file submited via the web, it hangs
when tring to "print TOSTDIN $input;".

Any ideas?  

Thanks,
David



------------------------------

Date: Mon, 31 Jan 2005 20:20:55 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Perl equivalent for Unix ps.
Message-Id: <HqwLd.189537$KO5.179600@clgrps13>

Michael Vilain wrote:
> In article <1107184846.240858.258510@c13g2000cwb.googlegroups.com>,
>  Prab_kar@hotmail.com wrote:
>>
>>I wanted to see if pure Perl can give me the same info that the running
>>ps from backticks or system("ps") would give.
>>Unfortunately, that doesnt seem to be the case.
> 
> what's wrong with opening a filehandle (e.g.
> 
> open (PS,"ps -ef") && die "can't open ps: $!\n";

Did you try that?  When you try to open the file 'ps -ef' what happens?


John
-- 
use Perl;
program
fulfillment


------------------------------

Date: Mon, 31 Jan 2005 14:55:57 -0800
From: Michael Vilain <vilain@spamcop.net>
Subject: Re: Perl equivalent for Unix ps.
Message-Id: <vilain-56030D.14555731012005@news.giganews.com>

In article <HqwLd.189537$KO5.179600@clgrps13>,
 "John W. Krahn" <someone@example.com> wrote:

> Michael Vilain wrote:
> > In article <1107184846.240858.258510@c13g2000cwb.googlegroups.com>,
> >  Prab_kar@hotmail.com wrote:
> >>
> >>I wanted to see if pure Perl can give me the same info that the running
> >>ps from backticks or system("ps") would give.
> >>Unfortunately, that doesnt seem to be the case.
> > 
> > what's wrong with opening a filehandle (e.g.
> > 
> > open (PS,"ps -ef") && die "can't open ps: $!\n";
> 
> Did you try that?  When you try to open the file 'ps -ef' what happens?

Nothing.  Again, I deservedly get spanked for not checking what I post.  
I'm running out of toes to shoot...

Anyway,

open (PS,"ps -ef |") && die "can't open ps: $!\n";

worked on Solaris under perl 5.003.  It doesn't seem to work on either 
of my Perl 5.6 systems (MacOS X or Linux).  So, you might try using a 
CPAN extension like Unix::Process

http://search.cpan.org/~jettero/Unix-Process-1.1.1/Process.pm

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...





------------------------------

Date: 31 Jan 2005 22:59:50 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl equivalent for Unix ps.
Message-Id: <slrncvte36.a9.abigail@alexandra.abigail.nl>

Michael Vilain (vilain@spamcop.net) wrote on MMMMCLXXI September MCMXCIII
in <URL:news:vilain-56030D.14555731012005@news.giganews.com>:
[]  In article <HqwLd.189537$KO5.179600@clgrps13>,
[]   "John W. Krahn" <someone@example.com> wrote:
[]  
[] > Michael Vilain wrote:
[] > > In article <1107184846.240858.258510@c13g2000cwb.googlegroups.com>,
[] > >  Prab_kar@hotmail.com wrote:
[] > >>
[] > >>I wanted to see if pure Perl can give me the same info that the running
[] > >>ps from backticks or system("ps") would give.
[] > >>Unfortunately, that doesnt seem to be the case.
[] > > 
[] > > what's wrong with opening a filehandle (e.g.
[] > > 
[] > > open (PS,"ps -ef") && die "can't open ps: $!\n";
[] > 
[] > Did you try that?  When you try to open the file 'ps -ef' what happens?
[]  
[]  Nothing.  Again, I deservedly get spanked for not checking what I post.  
[]  I'm running out of toes to shoot...
[]  
[]  Anyway,
[]  
[]  open (PS,"ps -ef |") && die "can't open ps: $!\n";

                         ^^

Did you try that? When you try to open the pipe, what happens?



Abigail
-- 
perl -wle '$, = " "; print grep {(1 x $_) !~ /^(11+)\1+$/} 2 .. shift'


------------------------------

Date: Mon, 31 Jan 2005 22:39:25 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Perl loops should use break, not last
Message-Id: <87pszl9qkg.fsf@mithril.chromatico.net>

>>>>> "JM" == Jeremy Morton <ask@me.com> writes:

    JM> Why does every genuine question to a Usenet group have to be a
    JM> troll?  See this is why I don't often post on bloody Usenet.

Asking and getting an answer is one thing.  Continuing to argue after
you get a clear answer is what makes you seem like a troll.

Perl uses "last" and "next", not "break" and "continue."  Perl is not
C; if you want C, go use C.  If you don't want C, but think Perl
should use these particular C keywords, you can write a source code
filter to change it.  Have fun.

Charlton


-- 
cwilbur at chromatico dot net
cwilbur at mac dot com


------------------------------

Date: Mon, 31 Jan 2005 10:46:43 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl newbie -  getting "system()" to return
Message-Id: <slrncvso7j.nc9.tadmc@magna.augustmail.com>

Jean-Benoit MORLA <jbmorla@tiscali.fr> wrote:


> system( executable1 );


You should put quotes around strings.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Mon, 31 Jan 2005 14:09:10 -0500
From: Steve Holden <steve@holdenweb.com>
Subject: Re: Q: quoting string without escapes
Message-Id: <usvLd.101064$Jk5.26160@lakeread01>

Xah Lee wrote:

> in Python, is there a way to quote a string as to avoid escaping ' or "
> inside the string?
> 
> i.e. like Perl's q or qq.
> thanks.
> 
>  Xah
>  xah@xahlee.org
>  http://xahlee.org/PageTwo_dir/more.html
> 
Aren't you the guy who's telling the whole world how to write Python and 
Perl? Unusual to find arrogance and humility in such close proximity.

Please stop cross-posting your ill-informed and inflammatory stuff to 
c.l.py and c.l.perl.m. And now I have your attention, the answer to your 
question is ...

     Use triple-quoting.

followups-set'ly y'rs  - steve
-- 
Steve Holden               http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC      +1 703 861 4237  +1 800 494 3119


------------------------------

Date: Mon, 31 Jan 2005 11:52:28 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: recursive function and hashe
Message-Id: <310120051152280897%jgibson@mail.arc.nasa.gov>

In article <41fe3748$0$4789$626a14ce@news.free.fr>, SÈbastien
Cottalorda <sppNOSPAM@libello.com> wrote:

> I all,
> 
> Here is my problem,
> 
> I'd like to store in a hash table those numbers like that:
> (123, 124, 13, 145, 2, 25)
> 
> %number = (
>         "1" => {
>                 "2" => {
>                         "3" => {
>                                 "value" => "OK"
>                         },
>                         "4" => {
>                                 "value" => "OK"
>                         },
>                 },
>                 "3" => {
>                         "value" => "OK"
>                 },
>                 "4" => {
>                         "5" => {
>                                 "value" => "OK"
>                         }
>                 }
>         },
>         "2" => {
>                 "value" => "OK",
>                 "5" => {
>                         "value" => "OK"
>                 }
>         }
> );
> 
> I think I need to use recursive function, but I did know how, I'm not
> familiar with passing references.

No, you don't. You can do this with loops. You can iterate over the
individual characters in a string scalar by splitting the string using
the empty pattern //:

#!/usr/local/bin/perl
#
use strict;
use warnings;

use Data::Dumper;

my %number;
while( my $num = <DATA> ) {
  chomp $num;
  my @digits = split(//,$num);
  my $ref = \%number;
  while( @digits ) {
    my $digit = shift @digits;
    if( @digits ) {
      if( exists ${$ref}{$digit} ) {
        $ref = $$ref{$digit};
      }else{
        $$ref{$digit} = {};
        $ref = ${$ref}{$digit};
      }
    }else{
      ${$ref}{$digit}{value} = 'OK';
    }
  }
}
print Dumper(\%number);
__DATA__
123
124
13
145
2
25

__OUTPUT__

$VAR1 = {
          '1' => {
                   '4' => {
                            '5' => {
                                     'value' => 'OK'
                                   }
                          },
                   '3' => {
                            'value' => 'OK'
                          },
                   '2' => {
                            '4' => {
                                     'value' => 'OK'
                                   },
                            '3' => {
                                     'value' => 'OK'
                                   }
                          }
                 },
          '2' => {
                   'value' => 'OK',
                   '5' => {
                            'value' => 'OK'
                          }
                 }
        };


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


------------------------------

Date: Mon, 31 Jan 2005 10:44:19 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: recursive function and hashe
Message-Id: <slrncvso32.nc9.tadmc@magna.augustmail.com>

Sébastien Cottalorda <sppNOSPAM@libello.com> wrote:
> I all,
> 
> Here is my problem,
> 
> I'd like to store in a hash table those numbers like that:
> (123, 124, 13, 145, 2, 25)
> 
> %number = (
>         "1" => {
>                 "2" => {
>                         "3" => {
>                                 "value" => "OK"
>                         },
>                         "4" => {
>                                 "value" => "OK"
>                         },
>                 },
>                 "3" => {
>                         "value" => "OK"
>                 },
>                 "4" => {
>                         "5" => {
>                                 "value" => "OK"
>                         }
>                 }
>         },
>         "2" => {
>                 "value" => "OK",
>                 "5" => {
>                         "value" => "OK"
>                 }
>         }
> );
> 
> I think I need to use recursive function, but I did know how,


---------------------
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

my %number;
foreach my $num ( 123, 124, 13, 145, 2, 25 ) {
   add_to_hash( \%number, $num );
}
print Dumper \%number;


sub add_to_hash {
   my($h, $num) = @_;

   if ( $num =~ s/^(\d)// ) {
      $h->{$1} = {} unless exists $h->{$1};
      add_to_hash($h->{$1}, $num);
   }
   else {
      $h->{value} = 'OK';
   }
}
---------------------


-- 
    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.  

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 7717
***************************************


home help back first fref pref prev next nref lref last post