[23914] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6116 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 11 14:10:49 2004

Date: Wed, 11 Feb 2004 11:10:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 11 Feb 2004     Volume: 10 Number: 6116

Today's topics:
    Re: UNIX Find on Windows <brian.getridofthis.bygland@boeingDELETEthis.com>
    Re: UNIX Find on Windows <brian.getridofthis.bygland@boeingDELETEthis.com>
        Using Tie::IxHash order a hash reference (Darius)
    Re: Using Tie::IxHash order a hash reference <usenet@morrow.me.uk>
    Re: Using Tie::IxHash order a hash reference <pinyaj@rpi.edu>
    Re: Using Tie::IxHash order a hash reference <noreply@gunnar.cc>
    Re: Using Tie::IxHash order a hash reference <noreply@gunnar.cc>
    Re: why does chomping a list remove all its elements (Jon Landenburer)
    Re: why does chomping a list remove all its elements <usenet@morrow.me.uk>
    Re: Why is Perl losing ground? <perl@my-header.org>
    Re: Why references?? thumb_42@yahoo.com
    Re: Why references?? <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Feb 2004 16:34:00 GMT
From: Brian <brian.getridofthis.bygland@boeingDELETEthis.com>
Subject: Re: UNIX Find on Windows
Message-Id: <402A5978.DCCC2E3D@boeingDELETEthis.com>

Thank you Eric.

Eric Schwartz wrote:
> 
> Brian <brian.getridofthis.bygland@boeingDELETEthis.com> writes:
> > I'm fairly new to using Perl on Windows.  I need to find all of the
> > files in a folder and its sub folders that match a pattern.  On UNIX I'd
> > do:
> >
> > $FOUND = `find $DIRROOT -name "$PATTERN" -print`;
> >
> > Is there a way to do this on Windows using Perl and/or native Windows
> > commands?
> 
> perldoc File::Find
> 
> also, see find2perl (in the standard distribution on Unix; I'd assume
> also on Windows), which converts find commands into equivalent (but
> not necessarily optimal) Perl programs that use File::Find.
> 
> -=Eric
> --
> Come to think of it, there are already a million monkeys on a million
> typewriters, and Usenet is NOTHING like Shakespeare.
>                 -- Blair Houghton.


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

Date: Wed, 11 Feb 2004 16:39:23 GMT
From: Brian <brian.getridofthis.bygland@boeingDELETEthis.com>
Subject: Re: UNIX Find on Windows
Message-Id: <402A5ABB.E593420D@boeingDELETEthis.com>

Thanks. I'll look at File::Find. This is a part of a fairly complex
script that I'm porting from UNIX to Windows. I'm trying to remove all
of the backtick/system commands that I can to make to portable.

Michele Dondi wrote:
> 
> On Tue, 10 Feb 2004 23:13:36 GMT, Brian
> <brian.getridofthis.bygland@boeingDELETEthis.com> wrote:
> 
> >$FOUND = `find $DIRROOT -name "$PATTERN" -print`;
> 
> BTW, it may be an idiosincrasy of mine, but I'd rather open() a find
> cmd in pipe and read 'while <$fh>' as usual...
> 
> >Is there a way to do this on Windows using Perl and/or native Windows
> >commands?
> 
> Using Perl: File::Find. Using native Windows commands: dir /b [/s]
> (but may not do exactlty what you mean!). Alternatively I, for one,
> have a straight find port from UNXUTILS.
> 
> But AFAICT I've never used a statement like the one above, the
> rationale being *IMHO* that if the task is simple enough to fit nicely
> in a series of piped commands on the cmd line, then find is the right
> tool for this, and Perl may not even be necessary whereas if the task
> is complex enough to deserve the full power of Perl, then I'd use
> File::Find instead.
> 
> Michele
> --
> you'll see that it shouldn't be so. AND, the writting as usuall is
> fantastic incompetent. To illustrate, i quote:
> - Xah Lee trolling on clpmisc,
>   "perl bug File::Basename and Perl's nature"


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

Date: 11 Feb 2004 08:35:38 -0800
From: dmedhora@yahoo.com (Darius)
Subject: Using Tie::IxHash order a hash reference
Message-Id: <26a5971.0402110835.7305310@posting.google.com>

Hi, 
How can I order the entries in a hash if I use a reference to a hash
instead of a hash. For e.g.

$ref={
key=>"value",
};

instead of

%ref=(
key=>"value",
);

Thanks!


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

Date: Wed, 11 Feb 2004 17:28:17 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Using Tie::IxHash order a hash reference
Message-Id: <c0donh$sd2$2@wisteria.csv.warwick.ac.uk>


dmedhora@yahoo.com (Darius) wrote:
> Hi, 
> How can I order the entries in a hash if I use a reference to a hash
> instead of a hash. For e.g.
> 
> $ref={
> key=>"value",
> };
> 
> instead of
> 
> %ref=(
> key=>"value",
> );

I'm not quite sure what you mean... is the answer you're looking for
    sort keys %$hash
? If not, tell us how you'd do waht yu want with a hash, and we'll
tell you how to do it with a hashref :).

Ben

-- 
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based 
on the strictest morality.  [Samuel Butler, paraphrased]       ben@morrow.me.uk


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

Date: Wed, 11 Feb 2004 12:38:20 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Darius <dmedhora@yahoo.com>
Subject: Re: Using Tie::IxHash order a hash reference
Message-Id: <Pine.SOL.3.96.1040211123735.8842C-100000@vcmr-86.server.rpi.edu>

[posted & mailed]

On 11 Feb 2004, Darius wrote:

>How can I order the entries in a hash if I use a reference to a hash
>instead of a hash. For e.g.

Tie a hash, using the hash reference.

  use Tie::IxHash;

  my $ref = {};
  tie %$ref, 'Tie::IxHash';

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Wed, 11 Feb 2004 18:40:58 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Using Tie::IxHash order a hash reference
Message-Id: <c0dpkv$15fve4$1@ID-184292.news.uni-berlin.de>

Ben Morrow wrote:
> I'm not quite sure what you mean... is the answer you're looking
> for
>     sort keys %$hash
> ? If not, tell us how you'd do waht yu want with a hash, and we'll 
> tell you how to do it with a hashref :).

The subject line indicates that OP wonders if Tie::IxHash (preserving
the original order, not necessarily a particular sort order) can be
used without a named hash.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Wed, 11 Feb 2004 18:43:53 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Using Tie::IxHash order a hash reference
Message-Id: <c0dpq8$15fve4$2@ID-184292.news.uni-berlin.de>

Jeff 'japhy' Pinyan wrote:
> On 11 Feb 2004, Darius wrote:
>> How can I order the entries in a hash if I use a reference to a
>> hash instead of a hash. For e.g.
> 
> Tie a hash, using the hash reference.
> 
>   use Tie::IxHash;
> 
>   my $ref = {};
>   tie %$ref, 'Tie::IxHash';

Did you try that, Jeff?

I did, and found that the original order is not preserved that way.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 11 Feb 2004 08:13:29 -0800
From: jon.m.landenburger@verizon.com (Jon Landenburer)
Subject: Re: why does chomping a list remove all its elements
Message-Id: <feee7535.0402110813.62673bb9@posting.google.com>

Interesting .  When I did:
#!/bin/perl
@files = ("AAAAA", "BBBBB", "CCCCC", "DDDDDD");
print @files;
print "chomped\n";
chomp @files;
print @files;

print "test2\n";
@files = ("AAAAA\n", "BBBBB\n", "CCCCC\n", "DDDDDD\n");
print @files;
print "chomped\n";
chomp @files;
print @files;

I got: 
AAAAABBBBBCCCCCDDDDDDchomped     ##No reult of chomp because no CR
AAAAABBBBBCCCCCDDDDDDtest2
AAAAA
BBBBB
CCCCC
DDDDDD
chomped
AAAAABBBBBCCCCCDDDDDD[Hit return to continue]   ## Yesiree it removed all the \n'
I learned something today.


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

Date: Wed, 11 Feb 2004 17:17:21 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: why does chomping a list remove all its elements
Message-Id: <c0do31$sd2$1@wisteria.csv.warwick.ac.uk>


Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:
> Why does the following not work?
> 
> open(FILES, "< musiclist2.txt");
> @files = <FILES>;
> print "unchomped\n";
> print @files;
> print "chomped\n";
> chomp @files;
> print @files;
> 
> It gives:
> 
> unchomped
> (Cream) - the very best of cream
> (Janis Joplin) - Greatest Hits
> (Jethro Tull) - Heavy Horses
> (Jethro Tull) - Thick As A Brick
> chomped

Chances are that your prompt is overwriting the last line of output:
it won't have a newline at the end, remember. Try adding 
    print "\n";
on the end.

Ben

-- 
  The cosmos, at best, is like a rubbish heap scattered at random.
                                                         - Heraclitus
  ben@morrow.me.uk


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

Date: Wed, 11 Feb 2004 20:00:43 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: Why is Perl losing ground?
Message-Id: <8iuk20tv1lo2l8laoqmnsipb5q6nho2nl5@4ax.com>

X-Ftn-To: Bart Lateur 

Bart Lateur <bart.lateur@pandora.be> wrote:
>>Are you aware that C isn't replaceable when it comes to platform
>>portability?
>
>C isn't portable, that's just an illusion. 

You're right, but note that I wrote platform[1] portability, not C
portability.

[1] such as OS, server, interpreter


-- 
Matija


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

Date: Wed, 11 Feb 2004 17:22:42 GMT
From: thumb_42@yahoo.com
Subject: Re: Why references??
Message-Id: <CxtWb.278795$xy6.1422971@attbi_s02>

Ben Morrow <usenet@morrow.me.uk> wrote:
 
> OK, if you say so... my reason for thinking otherwise is that I'm sure
> I've read either Tad or MJD, I forget which, writing that my scopes a
> variable whereas local scopes a variable's value.

This is kind of points out a case where references might be a bad idea,
the "who's variable/data/thing is it, *what* is it for that matter?" 
can get confusing, while:

sub fetch {
    return(%hash);
}

is pretty clear and straightforward since everything is passed "by-value".

sub fetch {
    return(\%hash);
}

Is faster, and a lot of folks perfer it, but it forces you to think how can
$hash_ref get modified? (Ok, more specifically, who/what/where can modify
the values that are referenced by $hash_ref) the effect is the same, you
have to be careful about modifying that data after you've returned the
reference. (unless this is what you want to do on purpose for some reason,
ex: the returned reference some how tracks the state of the package/scope it
was returned from or the reference that the caller is expected to append
text to/fill with values or something.

I suppose when you consider anonymous references, the idea of what a 
variable is and how it's scoped gets interesting. :-)

I don't think it's a particularly big deal in either case, but the original
question was "Why use a reference when you can just use a value".

I'd just use the value if the hash were something small, a record from a
tabfile or something. It eliminates the possibility of shooting myself in
the foot, there is no way the contents can unexpectedly change later on.

IMO, there is really nothing wrong with returning a reference either if thats
what you want to do. Heck, you could use wantarray() and return either
depending on the callers 'mood'.  :-)

Jamie


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

Date: Wed, 11 Feb 2004 17:37:34 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Why references??
Message-Id: <c0dp8u$sd2$3@wisteria.csv.warwick.ac.uk>


thumb_42@yahoo.com wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote:
>  
> > OK, if you say so... my reason for thinking otherwise is that I'm sure
> > I've read either Tad or MJD, I forget which, writing that my scopes a
> > variable whereas local scopes a variable's value.
> 
> This is kind of points out a case where references might be a bad idea,
> the "who's variable/data/thing is it, *what* is it for that matter?" 
> can get confusing, while:
> 
> sub fetch {
>     return(%hash);
> }
> 
> is pretty clear and straightforward since everything is passed "by-value".
> 
> sub fetch {
>     return(\%hash);
> }
> 
> Is faster, and a lot of folks perfer it, but it forces you to think how can
> $hash_ref get modified? (Ok, more specifically, who/what/where can modify
> the values that are referenced by $hash_ref) the effect is the same, you
> have to be careful about modifying that data after you've returned the
> reference. (unless this is what you want to do on purpose for some reason,
> ex: the returned reference some how tracks the state of the package/scope it
> was returned from or the reference that the caller is expected to append
> text to/fill with values or something.

You are conflating two questions here: 'do I want to return the
original data or a copy' and 'do I want to return the data as a list
or as a ref'. It is hard to return the original data as a list; but if
you want to return a ref you have a choice between

sub fetch { return \%hash }

and

sub fetch { return {%hash} }

 . Obviously there is no speed benefit to the second, but that *does*
*not* *concern* me: premature optimization is the root of all evil. If
the function is supposed to return a copy of the data that the caller
can do with what he will, then it should return a copy. If it is
supposed to return the actual data, such that modifications to the
return value modify the original data, then that is what it should
do. In either case, the decision *must not* be made on the basis of
unjustified assumptions about efficiency: there's time enough to deal
with that later, once you've got the logic right.

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * ben@morrow.me.uk *


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

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


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