[15554] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2967 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 6 14:10:31 2000

Date: Sat, 6 May 2000 11:10:21 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <957636620-v9-i2967@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 6 May 2000     Volume: 9 Number: 2967

Today's topics:
        Help:  How to Delete Problem Files on Multiple Disk Par <pangjo@hotmail.com>
    Re: Help:  How to Delete Problem Files on Multiple Disk <rootbeer@redcat.com>
    Re: How to print '%' character with printf ? msouth@fulcrum.org
    Re: How to print '%' character with printf ? <lr@hpl.hp.com>
    Re: How to strip Carriage Returns in a variable? <lyndon@xellent.co.uk>
    Re: How to strip Carriage Returns in a variable? <lr@hpl.hp.com>
    Re: Ignoring Bold Letters <rootbeer@redcat.com>
        Making my script not case-sensitive! <jetlund@tele.ntnu.no>
    Re: Making my script not case-sensitive! <tony_curtis32@yahoo.com>
    Re: Making my script not case-sensitive! (bowman)
    Re: Making my script not case-sensitive! <rootbeer@redcat.com>
    Re: Making my script not case-sensitive! <jetlund@tele.ntnu.no>
    Re: Need Freelance Perl Scripter (Tony L. Svanstrom)
        Parallel port <christian.goebel@luxmail.lu>
    Re: perl-corba documentation.. <rootbeer@redcat.com>
        perlcc <jcmarle@qis.net>
    Re: perlcc[more info] <jcmarle@qis.net>
    Re: perlcc[more info] <rootbeer@redcat.com>
    Re: PLEASE HELP on Hash of Hash <abe@ztreet.demon.nl>
    Re: problem with "system" and file copy (Villy Kruse)
    Re: problem with "system" and file copy (Tad McClellan)
    Re: problem with "system" and file copy <flavell@mail.cern.ch>
        Question on references... <propart@mediaone.net>
    Re: Question on references... <franl-removethis@world.omitthis.std.com>
    Re: Question on references... <propart@mediaone.net>
    Re: Question on references... <uri@sysarch.com>
    Re: Question on references... <propart@mediaone.net>
        Read data from a serail port <fichou@tiscalinet.it>
    Re: Read data from a serail port <rootbeer@redcat.com>
    Re: running Windows program from perl script <lyndon@xellent.co.uk>
    Re: seeking a more elegant grouping algorithm than this (Eric Smith)
    Re: What's become of perl-Expect? msouth@fulcrum.org
    Re: Why are files required to return true values? (Tad McClellan)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 6 May 2000 10:17:06 -0400
From: "JP" <pangjo@hotmail.com>
Subject: Help:  How to Delete Problem Files on Multiple Disk Partitions?
Message-Id: <tHVQ4.4$T.213@client>

Our company has been badly invaded by the Love-Letter virus over the past
few days.  Now the virus has been stopped but is a time for cleaning up the
clients' workstations.

I would like to write a Perl script to:

1.  recursively look into the different partitions of the client's hard
drives
2.  identify the infected files by file extension, size and date
3.  delete those files

I know how to check the files in a specific directory but I don't know how I
can do a recursive check from the root and also go into the different
partitions.  Please give me some guidance.  Thanks in advance

Joe








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

Date: Sat, 6 May 2000 09:24:51 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Help:  How to Delete Problem Files on Multiple Disk Partitions?
Message-Id: <Pine.GSO.4.10.10005060924220.6766-100000@user2.teleport.com>

On Sat, 6 May 2000, JP wrote:

> I know how to check the files in a specific directory but I don't know
> how I can do a recursive check from the root and also go into the
> different partitions.

Use the File::Find module. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 6 May 2000 15:00:25 GMT
From: msouth@fulcrum.org
Subject: Re: How to print '%' character with printf ?
Message-Id: <8f1c29$iod$1@inxs.ncren.net>

Larry Rosler <lr@hpl.hp.com> wrote:
> In article <391177B8.71FB022C@orga.com> on Thu, 04 May 2000 15:14:32 
> +0200, Ulrich Ackermann <uackermann@orga.com> says...
>> Daniel Courivaud wrote:
>> > found nothing in perldoc and faqs. I want to print a string containing
>> > '%' character:
>> > 50 % of the files
>> > and I try many things like  __    printf(" %i \% of the
>> > files",$percentage);  __  but none of them are working.
[snip]
> In the format string, there is no backslash ahead of the '%', and even 
> if there were it wouldn't work, because that isn't the escape convention 
> for [s]printf.

> perldoc -f sprintf

> ...

> Perl's sprintf permits the following universally-known conversions:
                                       ^^^^^^^^^^^^^^^^^
apparently not... :)

>    %%   a percent sign 

Okay, to make this post slightly useful I'll note that putting 
two special characters together is a common idiom for quoting
a single one of those characters (for example, to put single
quote marks into a text field in MySQL).  Just for future 
reference next time you're shooting in the dark.

-- 
Michael South                   |   http://fulcrum.org
Head Mathophile,                |   101 Canyon Run
fulcrum.org                     |   Cary NC  27513 USA
(msouth@fulcrum.org)            |   (919) 465-9074


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

Date: Sat, 6 May 2000 09:19:27 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How to print '%' character with printf ?
Message-Id: <MPG.137de5da381c131298aa13@nntp.hpl.hp.com>

In article <8f1c29$iod$1@inxs.ncren.net> on 6 May 2000 15:00:25 GMT, 
msouth@fulcrum.org <msouth@fulcrum.org> says...
> Larry Rosler <lr@hpl.hp.com> wrote:
> > In article <391177B8.71FB022C@orga.com> on Thu, 04 May 2000 15:14:32 
> > +0200, Ulrich Ackermann <uackermann@orga.com> says...
> >> Daniel Courivaud wrote:
> >> > ... I want to print a string containing '%' character:
> >> > 50 % of the files
> >> > and I try many things like  __    printf(" %i \% of the
> >> > files",$percentage);  __  but none of them are working.

 ...

> Okay, to make this post slightly useful I'll note that putting 
> two special characters together is a common idiom for quoting
> a single one of those characters (for example, to put single
> quote marks into a text field in MySQL).  Just for future 
> reference next time you're shooting in the dark.

While we're still at it, here's yet another way of solving this and 
similar problems:

printf ' %i %s of the files', $percentage, '%'; 

Escape conventions be damned! 

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 6 May 2000 16:46:37 +0100
From: "Lyndon Leggate" <lyndon@xellent.co.uk>
Subject: Re: How to strip Carriage Returns in a variable?
Message-Id: <39143fe5@news.server.worldonline.co.uk>

The way I normally do it is:

$somestring =~ s/[\r]//g;

Hopfully that'll work for you too.

Lyndon

"Alan Honsinger" <alan@igs.net> wrote in message
news:8es49h$edr$1@news.igs.net...
> Hi,
>
> Was wondering how I could strip carriage returns (^M) from a variable.
>
> Thanks,
>
> Alan
>
>




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

Date: Sat, 6 May 2000 09:34:48 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How to strip Carriage Returns in a variable?
Message-Id: <MPG.137de97e235df68398aa14@nntp.hpl.hp.com>

In article <39143fe5@news.server.worldonline.co.uk> on Sat, 6 May 2000 
16:46:37 +0100, Lyndon Leggate <lyndon@xellent.co.uk> says...
> The way I normally do it is:
> 
> $somestring =~ s/[\r]//g;
> 
> Hopfully that'll work for you too.

It will work for anyone.  But:

A character class containing one character can be written just as that 
character alone.  So:

  $somestring =~ s/\r//g;

And, has already been posted, when manipulating individual characters 
out of context, there is a much faster way to do it:

  $something =~ tr/\r//d;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 6 May 2000 09:10:53 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Ignoring Bold Letters
Message-Id: <Pine.GSO.4.10.10005060908450.6766-100000@user2.teleport.com>

On Sat, 6 May 2000, root wrote:

> But if the beginning of the sentence (#4) is bold, the bot doesn't index
> it. What do I need to do, to make the bot index the bold text as well?

Probably you want to find out what character sequences mean "start bold"
and "end bold", or whatever, and strip those out before trying to identify
the text of the string.

> I would like "#4  45x [432] blah boo far" to be turned into:
>   4,45,432,blah boo far 
> but I am having trouble dealing with the white space cause there are
> always 2 whites between #4 and 45x.

Maybe you want to use a pattern match instead of split.

Good luck with it!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 06 May 2000 18:02:31 +0200
From: Ola Jetlund <jetlund@tele.ntnu.no>
Subject: Making my script not case-sensitive!
Message-Id: <39144217.1C018E13@tele.ntnu.no>

Hi,

I'm using a script that reads all files in a directory and renames them.
I recently discovered that when I read the names of the files in the
directory it skips all with capital letters (since my naming convention)
uses small letters. I use the following code to read the directory:

opendir THISDIR, "." or die "Error: $!";
@filer = readdir THISDIR;

and then I operate on with:

foreach(@sfiles){
  // If file contains elements(which is listed whith small letters) from
my naming convention then rename... //
}

Is there something I could do so the renaming also would happen when a
file in the directory has an element that I have in my convention but
with one or more large letters??


regards

J




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

Date: 06 May 2000 11:13:23 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Making my script not case-sensitive!
Message-Id: <878zxnveqk.fsf@shleppie.uh.edu>

>> On Sat, 06 May 2000 18:02:31 +0200,
>> Ola Jetlund <jetlund@tele.ntnu.no> said:

> Hi, I'm using a script that reads all files in a
> directory and renames them.  I recently discovered that
> when I read the names of the files in the directory it
> skips all with capital letters (since my naming
> convention) uses small letters. I use the following code
> to read the directory:

> Is there something I could do so the renaming also would
> happen when a file in the directory has an element that
> I have in my convention but with one or more large
> letters??

I think you probably want the /i modifier for regexps, see
"perldoc perlre" but I find your post slightly confusing
so that may not be what you want.

If you post code you need help/advice with, please post
*real* code otherwise people have to guess what you're
really trying to do, and the bits you snip usually turn
out to be where the problem lies :-)

hth
t


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

Date: Sat, 06 May 2000 16:13:41 GMT
From: bowman@erehwon.foo (bowman)
Subject: Re: Making my script not case-sensitive!
Message-Id: <VwXQ4.835$Jf.3386@newsfeed.slurp.net>

Ola Jetlund <jetlund@tele.ntnu.no> wrote:
>
>foreach(@sfiles){
>  // If file contains elements(which is listed whith small letters) from
>my naming convention then rename... //
>}

You left out the interesting part. Do one of the varaitions on case 
insensitive regexes, lc the file name, etc to perform your test.



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

Date: Sat, 6 May 2000 09:29:39 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Making my script not case-sensitive!
Message-Id: <Pine.GSO.4.10.10005060928090.6766-100000@user2.teleport.com>

On Sat, 6 May 2000, Ola Jetlund wrote:

> foreach(@sfiles){
>   // If file contains elements(which is listed whith small letters) from
> my naming convention then rename... //
> }
> 
> Is there something I could do so the renaming also would happen when a
> file in the directory has an element that I have in my convention but
> with one or more large letters??

Maybe you mean that you want to make a regular expression match
insensitive to case. If that's it, check out the /i option, documented in
perlop. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 06 May 2000 18:35:04 +0200
From: Ola Jetlund <jetlund@tele.ntnu.no>
Subject: Re: Making my script not case-sensitive!
Message-Id: <391449B8.2E8D2369@tele.ntnu.no>

Tony Curtis wrote:

> >> On Sat, 06 May 2000 18:02:31 +0200,
> >> Ola Jetlund <jetlund@tele.ntnu.no> said:
>
> > Hi, I'm using a script that reads all files in a
> > directory and renames them.  I recently discovered that
> > when I read the names of the files in the directory it
> > skips all with capital letters (since my naming
> > convention) uses small letters. I use the following code
> > to read the directory:
>
> > Is there something I could do so the renaming also would
> > happen when a file in the directory has an element that
> > I have in my convention but with one or more large
> > letters??
>
> I think you probably want the /i modifier for regexps, see
> "perldoc perlre" but I find your post slightly confusing
> so that may not be what you want.
>
> If you post code you need help/advice with, please post
> *real* code otherwise people have to guess what you're
> really trying to do, and the bits you snip usually turn
> out to be where the problem lies :-)
>
> hth
> t

Okay I'm sorry - but here is the a code bit that works:


#!/usr/bin/perl
opendir THISDIR, "." or die "Error: $!";
@filer = readdir THISDIR;
closedir THISDIR;
@sfiles = sort(@filer);
$for0 = "ola";
$ett0 = "jetlund";
$hel0 = "ola_jetlund";
$i = 0;
print "\n";
foreach(@sfiles){
    if(($_ =~ $for0) and ($_ =~ $ett0))
    {
         $i = $i + 1;
         print "mv $_ ";
         printf ".ok/%s", $hel0 ;
         if($i < 10)
         {
              printf "_00%1.0f", $i;
          }
          if(($i > 9) and ($i < 100))
          {
               printf "_0%2.0f", $i;
          }
           print ".trt\n";
       }
}exit 0;



So my problem now is what if a filename contains "Ola" and "Jetlund" and
I want to rename this file in the same way to "ola_jetlund_###.trt" ?


J




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

Date: Sat, 6 May 2000 13:31:08 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Need Freelance Perl Scripter
Message-Id: <1ea7p7s.zmc0sm1wfk12gN%tony@svanstrom.com>

Andrew N. McGuire <andrew.mcguire@walgreens.com> wrote:

> Dave Lambrix wrote:
> > 
> > I am in need of a freelancer to do some Perl scripting for me. I'm
> > pressed for time on this project, so I need replies as soon as possible.
> > Please send contact information to webmaster@cpudetails.com and I will
> > follow up with project details and requirements.
> 
> So, let's summarize:
> 
> I need your help to write my program for me.  You had better hurry,
> because my homework is due tomorrow.  I posted this here, but am too lazy
> to check for follow-ups, so please waste your time and mail them to me,
> and I will tell you what you need to do. ;^)
> 
> I realize this is not what you mean, but many here will interpret it as
> that.

If you forget the fact that these postings aren't welcome in c.l.p.m. I
find the #1 irritating thing about it to be that he's the one in a hurry
and still we have to come runing to him just to find out what the job is
about...

But... since I am replying I am sending him a cc, I mean, hey, if he's
willing to pay what I ask I might consider doing it; so now it's his
turn to come runing to me. *LOL*


     /Tony
-- 
     /\___/\ Who would you like to read your messages today? /\___/\
     \_@ @_/  Protect your privacy:  <http://www.pgpi.com/>  \_@ @_/
 --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
 DSS: 0x9363F1DB, Fp: 6EA2 618F 6D21 91D3 2D82  78A6 647F F247 9363 F1DB
 ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
    \O/   \O/  ©1999-2000                                   \O/   \O/


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

Date: Sat, 6 May 2000 17:53:25 +0200
From: "Christian Goebel" <christian.goebel@luxmail.lu>
Subject: Parallel port
Message-Id: <8f1f3r$9sr8j$1@fu-berlin.de>

Hi,
how I can send a byte to the parallel port (linux,apache)?
Can you give me an example?
best regards,

Christian




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

Date: Sat, 6 May 2000 10:11:29 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: perl-corba documentation..
Message-Id: <Pine.GSO.4.10.10005061008210.6766-100000@user2.teleport.com>

On Fri, 5 May 2000, Joydeep Roy Chowdhury wrote:

> i want to learn about implementation of CORBA in Perl. where can I get
> started ?

Maybe you want to get an introductory book on Perl. Many folks around here
recommend O'Reilly's book, "Learning Perl". Once you've learned the
basics, you could search CPAN for a helpful module.

    http://search.cpan.org/search?mode=module&query=corba
    http://search.cpan.org/

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 6 May 2000 07:37:26 -0400
From: "Jim Marley" <jcmarle@qis.net>
Subject: perlcc
Message-Id: <kATQ4.4243$No6.16870033@news-read1.qis.net>

I'm running 5.005_3 and having trouble getting perlcc to work (at all).  Can
anyone give me guidance on what files need to be modified to get this thing
rolling?  I've read there were problems in the past - but honestly haven't
kept up.

Tks

Jim...




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

Date: Sat, 6 May 2000 07:42:37 -0400
From: "Jim Marley" <jcmarle@qis.net>
Subject: Re: perlcc[more info]
Message-Id: <bFTQ4.4244$No6.16871686@news-read1.qis.net>

Sorry, should have also mentioned I'm running it on NT4.0.

 I'm running 5.005_3 and having trouble getting perlcc to work (at all).
Can
 anyone give me guidance on what files need to be modified to get this thing
 rolling?  I've read there were problems in the past - but honestly haven't
 kept up.

 Tks

 Jim...






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

Date: Sat, 6 May 2000 09:16:51 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: perlcc[more info]
Message-Id: <Pine.GSO.4.10.10005060914080.6766-100000@user2.teleport.com>

On Sat, 6 May 2000, Jim Marley wrote:

>  I'm running 5.005_3 and having trouble getting perlcc to work (at all).

Well, installing 5.6 will (probably) help. But you know that it is still
experimental, right? And it won't make your program faster, cooler,
smaller, more secure, easier to read, write, maintain, or debug?

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 06 May 2000 19:25:48 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: PLEASE HELP on Hash of Hash
Message-Id: <b538hsob0gt3kvdvkvg78e4clmbknh5093@4ax.com>

On Fri, 05 May 2000 20:43:37 GMT, tvn007@my-deja.com wrote:

> Hi,
And a good day to you too
> 
> Could  someone please help me on this:
> 
> Below is my PERL script:
Perl script (see: perldoc perlfaq1)
> 
> #!/usr/local/bin/perl
#!/usr/local/bin/perl -w
use strict;
Adding '-w' and 'use strict;' will help you.

> 
> $data_file = 'test.out';
> %hash;
> open(DATA,$data_file) || die "cannot open\n";
Good to see a message, but adding '$!' and the filename to it makes it
more informative:
open DATA, $data_file or die "Cannot open '$file_name': $!";

> 	while (<DATA>){
You have a problem with indentation. The rest of the script is almost
unreadable :-(

> 		chomp;
> 		($order,$item,$value) = split /:/,$_;
> 			$hash{$order}{$item}=$value;
> 	}
> 
> 		foreach $ok(keys %hash){
> 			print "ok\n";
                              ^^^
> 		foreach $ok2( keys %{$hash{$ok}}){
> 			print "$ok2\t";
> 			$ok3= $hash{$ok}{$ok2};
> 			print "$ok3\n";
> 		}
> 		}
> 
> INPUT FILE: 'test.out'
> 
> order#1:potato:100
> order#2:potato:200
> order#1:meat:20
> order#2:meat:30
> 
> OUTPUT From the PERL script above:
No, that is not true. Please use Copy/Paste if you want to show your
code (it saves you a lot of typing aswell).
 ...

> However, I would like the output to print as follow:
> 
> 			meat		potato
> order#1			20		100
> order#2			30		200
> 
> Min.			20		100
> Max.			30		200
> Average			25		150

This is my simple version (without Min and Max):

#!/usr/bin/perl -w
use strict;

my(%hash, %items);

while (<DATA>) {
	chomp;
	my($order, $item, $value) = split /:/;
	$hash{$order}{$item} = $value;
	
	#summary info
	$items{$item}{cnt}++;
	
	$items{$item}{avg} = 0 unless exists $items{$item}{avg};
	$items{$item}{avg} *= ($items{$item}{cnt}-1)/$items{$item}{cnt};
	$items{$item}{avg} += $value/$items{$item}{cnt};
}

#print header:
print "order #\t";
print "\t$_" for (sort keys %items);
print "\n\n";

#print data
for my $order (sort keys %hash) {
	print "$order\t";
	for my $item (sort keys %items) {
		print "\t", exists($hash{$order}{$item})?
			$hash{$order}{$item}:
			"xxx";
	}
	print "\n";
}

#print summary
print "\n";
for my $summ ( qw/Cnt Avg/ ) {
	print "$summ\t";
	for my $item (sort keys %items) {
		printf "\t%0.0f", $items{$item}{lc $summ};
	}
	print "\n";
}

__DATA__
order#1:potato:100
order#2:potato:200
order#1:meat:20
order#2:meat:30

-- 
Good luck,
Abe


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

Date: 6 May 2000 11:55:46 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: problem with "system" and file copy
Message-Id: <slrn8h821c.3b9.vek@pharmnl.ohout.pharmapartners.nl>

On Thu, 04 May 2000 11:07:42 GMT,
     Andreas Boerner <andreas.boerner@icn.siemens.de> wrote:


>Hello,
>
>I have a problem with copy and a system call:
>
>When I enter at command prompt (UNIX) the following command, it works
>as expected:
>
>cp ~/dir1/*.c ~/dir2
>
>
>The following perl routine however does not work:
>
>use strict;
>my $command;
>my $rc;
>
>$command = "cp ~/dir1/*.c ~dir2";
>print $command;
>$rc = system($command);
>print "rc=$rc\n";
>
>
>it produces the following output:
>
>command=cp ~/dir1/*.c ~/dir2
>cp: cannot access ~/dir1/*.c
>rc=512
>
>
>Has anybody an idea, why this fails ???
>
>

(Assuming you lost the slash in ~dir2 above).

Running following code:

perl -we '
use strict;
my $command;
my $rc;

$command = "cp ~/dir1/*.c ~/dir2";
print $command;
$rc = system($command);
print "rc=$rc\n";
'

Produces the following results (and the files are copied).

cp ~/dir1/*.c ~/dir2rc=0


But only of standard shell understands what ~/ means, that is
standard bourne shell won't work, but if standard shell is 'bash',
'csh', or 'ksh' it would.


Your login shell might be ksh or csh, but perl could use bourne
shell to run the system command.


Villy


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

Date: Sat, 6 May 2000 10:05:44 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: problem with "system" and file copy
Message-Id: <slrn8h89lo.7e1.tadmc@magna.metronet.com>

On 5 May 2000 15:54:56 -0700, Petri Oksanen <Petri_member@newsguy.com> wrote:
>In article <Pine.GSO.4.10.10005050917470.6766-100000@user2.teleport.com>, Tom
>says...
>>> His problem is that he forgot to put $command inside quotes:
>>> $rc = system("$command");


That is Perl code.

The _perl interpreter_ sees those double quotes, and interpolates
the value of $command, so system() sees the _value_ of $command
alone. It does not "see" (get passed) the quotes. So the quotes 
are never sent to the shell.

   $rc = system($command);

system() (and hence the shell, if invoked by system()) will 
see _exactly_ the same thing when called this way.


>>You seem to be mistaken. The quote marks in that statement are merely
>>misleading. Cheers!


Hence, the quote marks are misleading because they are merely
"noise". They do not change how the code behaves.


>Perhaps you can explain to me then why these work:
>
>perl -we "system(\"echo Works fine on Win32\");"
          ^                                     ^
>perl -we 'system("echo Works fine on *ix");'
          ^                                 ^


The _command interpreter_ sees those double quotes, and uses
them to delimit the command line arguments. They are not
passed as part of the argument(s). The shell "consumes" them.

The perl interpreter never sees them.


>Exactly where am I wrong?


You are confusing what is special to who.

In the original case, perl processes the quotes.

In your new command line cases, the shell processes the quotes.

Quote characters mean different things to different interpreters.


>In the original code, this _works_:
>system("$command");
>
>This _doesn't_:
>system($command);


They both work identically.

If one works the other works. If one fails the other fails.

Please show some short and complete code that we can run
that shows different behavior when called those two ways.


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 6 May 2000 17:55:20 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: problem with "system" and file copy
Message-Id: <Pine.GHP.4.21.0005061753100.2874-100000@hpplus01.cern.ch>

On Fri, 5 May 2000, Morbus Iff wrote:

> When executing commands on the system, you must use backticks instead of 
                                             ^^^^???
> quotes:

You really need to learn more about what you're doing, before
continuing this campaign of confidently giving out misinformation.

Just what did you suppose system() was for, anyway?



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

Date: Sat, 06 May 2000 12:22:18 GMT
From: PropART <propart@mediaone.net>
Subject: Question on references...
Message-Id: <39140E4D.C5448EB@mediaone.net>

I was reading Perl In A Nutshell about creating a reference to an
anonymous array and was suprised that it wasn't something like $ref =
\(1,2,3);

Then I did an experiment (below) and looked at perlref.

#!/usr/local/bin/perl -w
use strict;
my @arr = (1,2,3);
my $refArr = \@arr;
my $refAnon = [1,2,3];
my $refList = \(1,2,3);
print @arr, "\n"; # prints 123
print @$refArr, "\n"; # same thing
print @$refAnon, "\n"; # also prints 123
print $$refList, "\n"; # scalar context, prints 3
print @$refList, "\n"; # why can't I do this?

/***
Perl ref sez...

Note that taking a reference to an enumerated list is not the same as
using square brackets--instead it's the same as creating a list of
references!

    @list = (\$a, \@b, \%c);
    @list = \($a, @b, %c);      # same thing!

As a special case, \(@foo) returns a list of references to the contents
of @foo, not a reference to @foo itself. Likewise for %foo.

***/

But I thought references were always simple scalars, not a list of
memory locations as @list above appears to be... Not sure what my
question is here, but I'm feeling somewhat puzzled, sort of like, I
thought I understood references better before I started.

-- Wm. C.









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

Date: Sat, 6 May 2000 12:49:11 GMT
From: Francis Litterio <franl-removethis@world.omitthis.std.com>
Subject: Re: Question on references...
Message-Id: <m38zxn4zeg.fsf@franl.andover.net>

PropART <propart@mediaone.net> writes:

> Perl ref sez...
> 
> Note that taking a reference to an enumerated list is not the same as
> using square brackets--instead it's the same as creating a list of
> references!
> 
>     @list = (\$a, \@b, \%c);
>     @list = \($a, @b, %c);      # same thing!

> But I thought references were always simple scalars, not a list of
> memory locations as @list above appears to be...

A reference is a scalar.  It's just that the syntax

	\($a, $b, $c)

creates a list of references.  It saves some typing, and you lose nothing
for it, because there's already a syntax for creating a reference to an
array:

	[1, 3, 5]
--
Francis Litterio
franl-removethis@world.std.omit-this.com
PGP public keys available on keyservers.


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

Date: Sat, 06 May 2000 15:07:32 GMT
From: PropART <propart@mediaone.net>
Subject: Re: Question on references...
Message-Id: <39143506.3F7B0034@mediaone.net>

> A reference is a scalar.  It's just that the syntax
>
>         \($a, $b, $c)
>
> creates a list of references.  It saves some typing, and you lose nothing
> for it, because there's already a syntax for creating a reference to an
> array:
>
>         [1, 3, 5]

Thanks for the reply. Yeah, I did see in both perlref and PIAN that that's
the syntax, but I just wondered if there's some deeper underlying reason in
the design of Perl to use two different operators here to create a reference.
It just struck me as kind of inconsistent-seeming.

I realize that this is all kind of vague. Not really a criticism or a
question...

-- Wm. C.




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

Date: Sat, 06 May 2000 16:17:45 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Question on references...
Message-Id: <x7k8h7wt3v.fsf@home.sysarch.com>

>>>>> "P" == PropART  <propart@mediaone.net> writes:

  >> \($a, $b, $c)
  >> 
  >> creates a list of references.  It saves some typing, and you lose nothing
  >> for it, because there's already a syntax for creating a reference to an
  >> array:
  >> 
  >> [1, 3, 5]

  P> Thanks for the reply. Yeah, I did see in both perlref and PIAN that
  P> that's the syntax, but I just wondered if there's some deeper
  P> underlying reason in the design of Perl to use two different
  P> operators here to create a reference.  It just struck me as kind of
  P> inconsistent-seeming.


you don't grok the reasons for the different ways. \@a is for when you
have an existing array and want to pass a ref to it. [@a] is used to
create a new anonymous array and get a ref to that. that new ref has
freash copies of the data and can be passed around and won't get
destroyed as long at its ref count is > 0. there are place where the
uses overlap but that is not inconsistancy:

sub foo {
	my( @a ) = shift ;
	return \@a;
}

is the functional equivilent to :

sub foo {
	return [ shift() ] ;
}


uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Sat, 06 May 2000 17:19:48 GMT
From: PropART <propart@mediaone.net>
Subject: Re: Question on references...
Message-Id: <39145406.D1C9B7E9@mediaone.net>

> you don't grok the reasons for the different ways.

> [@a] is used to create a new anonymous array and get a ref to that. that new ref
> has

> freash copies of the data and can be passed around and won't get
> destroyed as long at its ref count is > 0.

My difficulty is definitely a grokking thing, because I've never really used
anonymous arrays.

So, I guess you'd use an anonymous array when you just want to start out with
array's values for some reason and you don't need a named array hanging around? I
should probably show up at the Boston PM meetings if I want to improve my Perl.

Thanks for the feedback,

-- William C.



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

Date: Sat, 6 May 2000 14:22:33 +0200
From: "Patrick Fichou" <fichou@tiscalinet.it>
Subject: Read data from a serail port
Message-Id: <8f12q9$6jm$1@serv1.albacom.net>

Hi,

I need to read data from my serial port... What do I have to do to :

- Configure the port (Speed, Parity...)
- Open the port
- Read the port
- Save the data in a text file
- Loop
- Close the port
- Exit

Thank you very much !

Patrick





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

Date: Sat, 6 May 2000 09:23:46 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Read data from a serail port
Message-Id: <Pine.GSO.4.10.10005060920520.6766-100000@user2.teleport.com>

On Sat, 6 May 2000, Patrick Fichou wrote:

> I need to read data from my serial port... What do I have to do to :

Checking the FAQ would be a good start. In section eight, you'll find "How
do I read and write the serial port?"

Checking CPAN for useful modules may also help.

    http://search.cpan.org/search?mode=module&query=serialport
    http://search.cpan.org/

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 6 May 2000 16:47:38 +0100
From: "Lyndon Leggate" <lyndon@xellent.co.uk>
Subject: Re: running Windows program from perl script
Message-Id: <39143fe6@news.server.worldonline.co.uk>

I have a similar problem ... if anyone can help that'll be great.

Thanks,

Lyndon

<colardelle@my-deja.com> wrote in message
news:8ebvtt$l6a$1@nnrp1.deja.com...
> Hello,
>
> I am quite new with perl, so it may be a very simple question. I am
> writing perl scripts on a W95 PC and I would like to run Windows
> programs (ie NOTEPAD) from a Perl script.
>
> Thanks in advance.
>
> Daniel
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




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

Date: 6 May 2000 15:10:48 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: Re: seeking a more elegant grouping algorithm than this ...
Message-Id: <slrn8h8dfo.t0u.eric@plum.fruitcom.com>


Rick

I am very grateful for your help.

Eric

:)

Rick Delaney posted
 > Assuming the data is sorted and in a file and ignoring your code
 > completely, here is a simple way.
 > 
 > #!/usr/bin/perl -w
 > 
 > use strict;
 > 
 > $_ = <>;
 > my ($prev, $second, $third) = split /,/;
 > my $index   = "$second$third";
 > my @current = $_;
 > my %result;
 > 
 > while(<>) {
 >     my ($first,$second,$third) = split /,/;
 >     if ($first ne $prev) {
 >     	push @{ $result{$index} }, @current;
 > 	$index   = "$second$third";
 > 	@current = $_;
 >     }
 >     else {
 >     	$index .= "$second$third";
 >     	push @current, $_;
 >     }
 >     $prev = $first;
 > }
 > push @{ $result{$index} }, @current;
 > 
 > for my $key (sort keys %result) {
 >     print map "$key,$_" => @{ $result{$key} };
 > }
 > 
 > 
 > -- 
 > Rick Delaney
 > rick.delaney@home.com



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

Date: 6 May 2000 14:27:22 GMT
From: msouth@fulcrum.org
Subject: Re: What's become of perl-Expect?
Message-Id: <8f1a4a$hfs$1@inxs.ncren.net>

Steven Faria <safaria@mindspring.com> wrote:
> Am having fun thinking that a fine product like Expect may be bundled in a
> Perl module.  Have heard that such a module has been around since 1998 but
> that it may not be ready for prime time.  (A follow-on from Comm.pm?)

> Looking forward to passwd edits and such. . .any caveats, alternatives?

A reply to this, telling where to get the module and showing sample
code using it, is on comp.lang.perl.modules .  If you are going to
ask the same question in two newsgroups, crosspost it so that people
don't have to answer it twice.

-- 
Michael South                   |   http://fulcrum.org
Head Mathophile,                |   101 Canyon Run
fulcrum.org                     |   Cary NC  27513 USA
(msouth@fulcrum.org)            |   (919) 465-9074


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

Date: Sat, 6 May 2000 10:21:25 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Why are files required to return true values?
Message-Id: <slrn8h8aj5.7e1.tadmc@magna.metronet.com>

On Fri, 05 May 2000 20:37:45 -0500, David Allen <s2mdalle@titan.vcu.edu> wrote:

>If I write a new module called Foo.pm, then of course before I run it, 
>it has to return a true value.  Why is that? 


All of the messages that perl might issue are documented
in 'perldiag.pod'.

The description of '%s did not return a true value' offers
a reason for that.

Is there some part of that reason that you have a further
question about?

If so, which part?



>but why a true
>value specifically? Most people just put
>
>1;
>
>and they're done with it.  why true?  Why couldn't you put
>
>undef;
>
>and have it work?


Then how would the module signal that it has a problem,
should it encounter one?


>Is there a syntactic or historical reason why perl requires this?


   perldoc -f use

says that "use" does a "require".

The same reason given in perldiag.pod is also given in

   perldoc -f require


Though only said twice instead of the usually required three times,
it is probably true nonetheless  :-)


>Because all it is to me is something that I have to fire my editor
                   ^^^^^
>back up to correct before I can test my module for the first time. :)


But you are not the only Perl programmer.

One of the others may be relying on that behavior.  :-)


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 2967
**************************************


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