[22804] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5025 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 22 14:06:16 2003

Date: Thu, 22 May 2003 11:05:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 22 May 2003     Volume: 10 Number: 5025

Today's topics:
    Re: Array and Hash headache <uri@stemsystems.com>
    Re: Array and Hash headache <barryk2@SPAM-KILLER.mts.net>
    Re: Array and Hash headache <goedicke@goedsole.com>
    Re: Array and Hash headache <jurgenex@hotmail.com>
    Re: Best way to compare binary files? <je@brighton.ac.uk>
    Re: Can I save my sourcecode from the Perl debugger? (Peter Scott)
        Changing STDOUT_TOP dynamically <shkumar@nospam.com>
    Re: Changing STDOUT_TOP dynamically <wksmith@optonline.net>
        Copying all files in a directory (Naina)
    Re: Copying all files in a directory (Helgi Briem)
        day of week <cyberjeff@sprintmail.com>
    Re: day of week <R-Yrreg@wiu.edu>
    Re: day of week <karabot@canada.com>
    Re: day of week <garry@ifr.zvolve.net>
    Re: DBI - 0 is not being treated as False ? ctcgag@hotmail.com
    Re: eval question <cwilbur@mithril.chromatico.net>
    Re: eval question <uri@stemsystems.com>
    Re: Finding files and moving them in perl (Sara)
    Re: help me with these guts <ericw@nospam.ku.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 22 May 2003 13:07:11 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Array and Hash headache
Message-Id: <x78ysz3zb4.fsf@mail.sysarch.com>

>>>>> "WG" == William Goedicke <goedicke@goedsole.com> writes:

  >> %category = (
  >> category01 => '$data1',
  >> category02 => '$data2',
  >> category03 => '$data3',
  >> category04 => '$data4',
  >> );

  WG> Use double-quotes instead of single quotes.
  WG> Goedicke: "Godlike"

that respell is not too accurate even by redmond standards. double
quotes on single scalar vars is not needed and can be buggy. see a recent
post on this subject which refers to an FAQ.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 22 May 2003 08:22:00 -0500
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: Array and Hash headache
Message-Id: <MPG.19368af7620e5dca9897db@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <4n3za.2321$Y57.66762@newsfep1-win.server.ntli.net>, Gary 
Mayor (abertron@btconnect.com) says...
> $data1 = "one";
> $data2 = "two";
> $data3 = "three";
> $data4 = "four";
> 
> %category = (
> category01 => '$data1',
> category02 => '$data2',
> category03 => '$data3',
> category04 => '$data4',
> );
> 
> print $category{category01};
> print $category{category02};
> print $category{category03};
> print $category{category04};
> 
> 

$data1 = "one";
$data2 = "two";
$data3 = "three";
$data4 = "four";

%category = (
category01 => $data1,
category02 => $data2,
category03 => $data3,
category04 => $data4,
);

print $category{category01};
print $category{category02};
print $category{category03};
print $category{category04};


-- 
---------

Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com


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

Date: Thu, 22 May 2003 13:33:42 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: Array and Hash headache
Message-Id: <m3y90zm7gw.fsf@mail.goedsole.com>

Dear Tad - 

tadmc@augustmail.com (Tad McClellan) writes:

> William Goedicke <goedicke@goedsole.com> wrote:
> 
> > Use double-quotes instead of single quotes.
> 
> No, use NO quotes instead of single quotes.

Thanks for being so gentle on me for that ridiculously stupid answer I
gave.  I'll try to be a little less blithe when I post in the future.

     Yours -      Billy

============================================================
     William Goedicke     goedicke@goedsole.com            
                          http://www.goedsole.com:8080      
============================================================

          Lest we forget:

You're wasting your time talking to Billy about
current pop culture..

		- Ted Silva


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

Date: Thu, 22 May 2003 13:35:21 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Array and Hash headache
Message-Id: <tm4za.39296$Hy3.8784@nwrddc02.gnilink.net>

Gary Mayor wrote:
> Hi,
> This is my first post on this newsgroup so please accuse me if it's in
> the wrong place.
> Basically i'm trying to put a string into a hash but the string won't
> go in. Here's the hash.
>
> $data1 = "one";
> $data2 = "two";
> $data3 = "three";
> $data4 = "four";
>
> %category = (
> category01 => '$data1',

Your problem has nothing to do with arrays or hashes but with quoting (you
would have exactly the same issue if would just try to print '$data1').

By using single quotes you are explicitely asking Perl to put the literal
text
    $data1
into your hash.
If you want Perl to interpret this as a variable name then you should tell
Perl so by using double quotes instead
    category01 => "$data1",
or even better don't use any quotes at all because there is no good reason
to stringify the text again
    category01 => $data1,

For further details please see "perldoc perlop", section Quote and
Quote-like Operators and "perldoc -q quote": "Do I always/never have to
quote my strings or use semicolons and commas?"

jue




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

Date: Thu, 22 May 2003 13:13:51 +0100
From: John English <je@brighton.ac.uk>
Subject: Re: Best way to compare binary files?
Message-Id: <baies6$9th$1@saturn.bton.ac.uk>

Randal L. Schwartz wrote:
> And if you don't want to type all this in every time, use File::Compare
> in the CPAN.

Ahhhh, right. Many thanks.

-----------------------------------------------------------------
  John English              | mailto:je@brighton.ac.uk
  Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
  Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
  University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



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

Date: Thu, 22 May 2003 13:21:10 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: Can I save my sourcecode from the Perl debugger?
Message-Id: <a94za.43516$ro6.1262287@news2.calgary.shaw.ca>

In article <776e0325.0305220432.59be5381@posting.google.com>,
 genericax@hotmail.com (Sara) writes:
>genericax@hotmail.com (Sara) wrote in message news:<776e0325.0305210944.24c8ce28@posting.google.com>...
>> Ack- I have a debug session open with my current sources loaded, but
>> in the meantime a sysadmin clobbered all of my sourcecode. Is there
>> any way to save the sources from the debugger? I looked at debug help
>> and searched this group I don't see it.
>> 
>> I know I could list the whole script and save it but is there a way to
>> export it to a file?
>
>Well it wasn't pretty, but I did "f" to go to each module, then listed
>all of the lines in the module to the terminal, then cut and pasted
>into vi and saved it.
>
>Only problem was that it also included line-numbers and varying
>numbers of leading spaces and occasional ":"s after the number. A
>quick Perlscript fixed that and we're back in business.

Congratulations, good thinking.

>If there is an easier way please advise me. I didn't see any in help
>of in newsgroups..

For each source file foo:

	DB<1> open FILE, ">foo.sav"
	DB<2> print FILE @{"_<foo"}
	DB<3> close FILE

Then strip the first line off foo.sav (or don't save it in the first place,
but I left that out because it would obscure the example).

perldoc perldebguts

>And if there ISN'T an easier way- hey debug dudes, this is a useful
>thing to be able to do!

??? Just how often do you think it happens that someone loses their
source code while they have a debugging session open on it???  Hands
up anyone else this has happened to.

Can you think of any *other* reason to want to save source code from
the debugger?

>By the way I also tried to redirect the listing to a file, but the ">"
>seemed to be ignored, and I tried to pipe to vi as well.

Not in the debugger command suite (the ways you tried).  You could
either "o pager=vi" or reassign DB::OUT, but the method above is easier.

-- 
Peter Scott
http://www.perldebugged.com


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

Date: 22 May 2003 06:47:36 -0700
From: Shreyas Kumar <shkumar@nospam.com>
Subject: Changing STDOUT_TOP dynamically
Message-Id: <baikdo0220e@drn.newsguy.com>

It seems Perl does not accept variables inside STDOUT_TOP, 
like the way it accepts STDOUT.

format STDOUT_TOP=
----------------------------------------
Table             |Used      |Allocated|
                  |space     |space    |
                  |@<<<<<<<<<|@<<<<<<<<|
----------------------------------------
$w_msg,$w_msg
 .

I want to print at the top either Used space (MB) or Used space (Blocks),
depending on what the user wants. So I am storing "MB" or "Blocks" in
a variable $w_msg which I want to substitute in the header as shown above.
It does not work.

So how I can do it.

Thanks.



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

Date: Thu, 22 May 2003 15:38:58 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Changing STDOUT_TOP dynamically
Message-Id: <ma6za.3462$Pz3.1913112@news4.srv.hcvlny.cv.net>


"Shreyas Kumar" <shkumar@nospam.com> wrote in message
news:baikdo0220e@drn.newsguy.com...
> It seems Perl does not accept variables inside STDOUT_TOP,
> like the way it accepts STDOUT.
>
> format STDOUT_TOP=
> ----------------------------------------
> Table             |Used      |Allocated|
>                   |space     |space    |
>                   |@<<<<<<<<<|@<<<<<<<<|
> ----------------------------------------
> $w_msg,$w_msg
> .
>
> I want to print at the top either Used space (MB) or Used space
(Blocks),
> depending on what the user wants. So I am storing "MB" or "Blocks" in
> a variable $w_msg which I want to substitute in the header as shown
above.
> It does not work.
>
> So how I can do it.
>
> Thanks.
>

 format STDOUT_TOP=
 ----------------------------------------
 Table             |Used      |Allocated|
                   |space     |space    |
                   |@<<<<<<<<<|@<<<<<<<<|
 $w_msg,$w_msg
 ----------------------------------------
 .

In general, I recommend against using write/format at all.  The
documentation in perldoc perlform falls far short of what I have come to
expect from the rest of the online documentation.  Your application may
be the exception where the _TOP feature provides a significant
advantage.

Bill




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

Date: 22 May 2003 06:51:53 -0700
From: naina_r@yahoo.com (Naina)
Subject: Copying all files in a directory
Message-Id: <5622768f.0305220551.69d85f17@posting.google.com>

Hi 
I used File::Copy and what I was able to do was copy some specific files.
Can i copy all files in a directory to another directory?I tried *.*,it doesnt
work.For example i need to copy all files in newdir to temp...
Eg 
copy ("C:/temp/newdir/*.*", "k:/temp/*.*");


Any suggestion would be welcome.
Thanks
Naina


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

Date: Thu, 22 May 2003 14:10:43 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Copying all files in a directory
Message-Id: <3eccd69d.3625496618@news.cis.dfn.de>

On 22 May 2003 06:51:53 -0700, naina_r@yahoo.com (Naina)
wrote:

>Hi 
>I used File::Copy and what I was able to do was copy some specific files.
>Can i copy all files in a directory to another directory?I tried *.*,it doesnt
>work.For example i need to copy all files in newdir to temp...
>Eg 
>copy ("C:/temp/newdir/*.*", "k:/temp/*.*");

Well, as our occasionally resident guru, Mark Jason Dominus,
once said:

"#11901 You can't just make s**t up and expect the computer 
to know what you mean, R******!"

If you had bothered to read the documentation for
the abovementioned module, that would have helped.

perldoc File::Copy

You have to produce the list of files to copy
yourself.  

The most common way is via opendir and readdir,

Here's one way to do it:

#!perl
use warnings;
use strict;
use File::Copy;
my $olddir = 'C:/temp/newdir';
my $newdir = 'K:/temp';
opendir DIR, $olddir or die "Cannot open dir $olddir:$!\n";
my @files = grep !/^\.{1,2}$/, readdir DIR;  # skip . and ..
closedir DIR;
FILE: for (@files)
{
	if (not copy "$olddir/$_", "$newdir/$_") 
	{ 
	warn "Cannot copy $_ from $olddir to $newdir"; 
	next FILE;
	}
	print "Copied $_ from $olddir to $newdir\n";
}
__END__
-- 
Regards, Helgi Briem
helgi DOT briem AT decode DOT is


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

Date: Thu, 22 May 2003 14:35:37 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: day of week
Message-Id: <3ECCDEF5.4AC72F5B@sprintmail.com>

  I'm looking for a no module way of extracting the day of week (tue)
from date strings like 05/21/03.


  I know I can do this:

my $time=localtime();
if($time=~/^(\w*)\s/){
$weekday=$1;
}

I'm unsure of how to convert '05/21/03' into something that localtime
can munch on. And I strongly suspect that there is probably a much
easier way to do this!

  Cheers,
Jeff


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

Date: Thu, 22 May 2003 09:42:55 -0500
From: Ryan Yrreg <R-Yrreg@wiu.edu>
Subject: Re: day of week
Message-Id: <bainlg$bj9$1@mail1.wiu.edu>

Try the Date::Calc module.  It can do pretty much everything date 
oriented.  I know it can do what you are looking for, but I don't 
remember the function name.  There is also an object oriented interface 
to Date::Calc if that interests you.
http://search.cpan.org/author/STBEY/Date-Calc-5.3/

Jeff Thies wrote:
>   I'm looking for a no module way of extracting the day of week (tue)
> from date strings like 05/21/03.
> 
> 
>   I know I can do this:
> 
> my $time=localtime();
> if($time=~/^(\w*)\s/){
> $weekday=$1;
> }
> 
> I'm unsure of how to convert '05/21/03' into something that localtime
> can munch on. And I strongly suspect that there is probably a much
> easier way to do this!
> 
>   Cheers,
> Jeff



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

Date: Thu, 22 May 2003 10:55:01 -0400
From: "George Karabotsos" <karabot@canada.com>
Subject: Re: day of week
Message-Id: <bx5za.6099$c41.662665@news20.bellglobal.com>

Check the Time::Local module, it contains functionality that does the
reverse of localtime(); i.e. you should be able to pass the year, month,
day, etc, and it will give you the number of seconds since the epoch.  Then
you can use the result through localtime() and get the day of the week.

Hope it helps,

George

"Jeff Thies" <cyberjeff@sprintmail.com> wrote in message
news:3ECCDEF5.4AC72F5B@sprintmail.com...
>   I'm looking for a no module way of extracting the day of week (tue)
> from date strings like 05/21/03.
>
>
>   I know I can do this:
>
> my $time=localtime();
> if($time=~/^(\w*)\s/){
> $weekday=$1;
> }
>
> I'm unsure of how to convert '05/21/03' into something that localtime
> can munch on. And I strongly suspect that there is probably a much
> easier way to do this!
>
>   Cheers,
> Jeff




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

Date: Thu, 22 May 2003 17:52:33 -0000
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: day of week
Message-Id: <slrnbcq3j4.pbr.garry@zfw.zvolve.net>

On Thu, 22 May 2003 14:35:37 GMT, Jeff Thies
<cyberjeff@sprintmail.com> wrote:

>   I'm looking for a no module way of extracting the day of week (tue)
> from date strings like 05/21/03.
> 
>   I know I can do this:
> 
> my $time=localtime();
> if($time=~/^(\w*)\s/){
> $weekday=$1;
> }
> 
> I'm unsure of how to convert '05/21/03' into something that localtime
> can munch on. 

Use the core module Time::Local.  

> And I strongly suspect that there is probably a much
> easier way to do this!

    #!/usr/local/bin/perl
    use strict;
    use warnings;
    use Time::Local;

    my %dow = ( 0 => 'Sunday',    1 => 'Monday',   2 => 'Tuesday',
		3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday',
		6 => 'Saturday' );

    my $date = '05/21/03';

    my ($mm, $da, $yr) = split m#/#, $date;

    my $then = timelocal 0, 0, 0, $da, $mm - 1, $yr + 1900;

    print "day of week is ", $dow{(localtime $then)[6]}, "\n";

    __END__

-- 
Garry Williams


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

Date: 22 May 2003 15:54:57 GMT
From: ctcgag@hotmail.com
Subject: Re: DBI - 0 is not being treated as False ?
Message-Id: <20030522115457.241$rx@newsreader.com>

"Kasp" <kasp@epatra.com> wrote:
> I read recently....
> "DBI plays a magic trick so that the value it turns is true even when it
> is 0."
> [source = http://www.perl.com/pub/a/1999/10/DBI.html ]
>
> Can some one please explain how this can be done?
> I find this bizarre, because 0 is false in Perl.

The string "0" is false in Perl.  The string "0e0" is true, but
evaluates to zero in a numeric usage.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Thu, 22 May 2003 13:41:46 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: eval question
Message-Id: <8765o3umyw.fsf@mithril.chromatico.net>

Uri Guttman <uri@stemsystems.com> writes:

> you should almost never need eval. eval is a LAST resort thing and
> not a first tool to use. newbies in general never need eval, they
> just think they do.

Sometimes the eval code can be shorter and just as clear.  This oldbie
tends to use it then.

Charlton


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

Date: Thu, 22 May 2003 13:54:06 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: eval question
Message-Id: <x7wugj2ikh.fsf@mail.sysarch.com>

>>>>> "CW" == Charlton Wilbur <cwilbur@mithril.chromatico.net> writes:

  CW> Uri Guttman <uri@stemsystems.com> writes:
  >> you should almost never need eval. eval is a LAST resort thing and
  >> not a first tool to use. newbies in general never need eval, they
  >> just think they do.

  CW> Sometimes the eval code can be shorter and just as clear.  This oldbie
  CW> tends to use it then.

but you are then making a conscious decision and have a valid reason to
support it. newbies who just use eval since it seems cool or they have
seen other (bad) code use it are not thinking about it. that is the real
evil part. so downplaying its use for them is good. eval is important
and useful but not a bandaid for poor coding skills.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 22 May 2003 08:06:14 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: Finding files and moving them in perl
Message-Id: <776e0325.0305220706.3699e7a5@posting.google.com>

dwlepage@yahoo.com (david) wrote in message news:<b09a22ae.0305201813.138fefa8@posting.google.com>...
> Im wondering if someone can help me with this simple perl problem. I
> have files in a directory /opt/scripts of the format:
> QF12345
> DF12345
> QF23456
> DF23456
> 
> If I find files that start with QF(.*) and DF$1 I want to copy them to
> a different directory. I've been toying with File::Find and
> File::Copy, and seem to have a way to find and a seperate way to copy
> the files but cannot seem to implement the right solution. Here is
> what I have so far:
> 
> #!/usr/bin/perl
> 
> use strict;
> use File::Find;
> use File::Copy;
> 
> sub findfile {
> if ($File::Find::name=~/QF(.*)/i or $File::Find::name=~/DF$1/i) {
> print $File::Find::name;
> print "\n";
> 
> }
> }
> 
> find \&findfile, '/opt/scripts';
> 
> Any idea how I can get the files I find to then copy them to a
> seperate directory?
> 05-22-2003 08:05
> Thanks!
> 
> Dave


I'd try this (untested) :

   my @files = grep /(file filter)/, readdir $mydir;
# now I have a filtered list of files.. 

   
  for (@files)
   {die "I cant copy $_, $!" unless copy $_, $dest_dir;
   }
 
  print "spiffy this seemed to work!\n";


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

Date: Thu, 22 May 2003 13:33:33 GMT
From: Eric Wilhelm <ericw@nospam.ku.edu>
Subject: Re: help me with these guts
Message-Id: <pan.2003.05.22.08.30.14.783629.8205@nospam.ku.edu>

On Thu, 22 May 2003 07:43:27 -0500, Sara wrote:

> Not sure exactly what you're trying to do, but on the surface it looks
> like you're a c-programmer who is trying to make his Perl look as much
> like c as you can.

No, I'm a Perl programmer who is trying to use as little C as possible to
create an interface to a C library which is usable from Perl:)

SWIG is a wrapper generator system.

The typemap is a chunk of code which gets spliced into the wrapped
function to translate the C variables to Perl and vica-versa.

It is basically like building an XS module, but with less coding.

The perl-looking variables are just SWIG's way of handling the C
variables.  They all get replaced with things like argvi and such.

--Eric


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5025
***************************************


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