[24527] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6707 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 19 09:05:40 2004

Date: Sat, 19 Jun 2004 06:05:05 -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           Sat, 19 Jun 2004     Volume: 10 Number: 6707

Today's topics:
    Re: $NF for perl (Anno Siegel)
    Re: Can't locate package AutoLoader for @File::List::IS <kayp511-w@yahoo.com>
        Embedding perl in Java (Shalini Joshi)
    Re: float storage <tassilo.parseval@rwth-aachen.de>
        how to import env (Lee)
    Re: how to import env <invalid-email@rochester.rr.com>
    Re: Random letters, getting same results <bik.mido@tiscalinet.it>
        remove redundant elements in an array <yzhan@andrew.cmu.edu>
    Re: remove redundant elements in an array <matthew.garrish@sympatico.ca>
    Re: remove redundant elements in an array <invalid-email@rochester.rr.com>
    Re: remove redundant elements in an array <jurgenex@hotmail.com>
    Re: sorting text jamasd@hotmail.com
    Re: sorting text (Anno Siegel)
    Re: Text Parsing <invalid-email@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 19 Jun 2004 12:14:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: $NF for perl
Message-Id: <cb1anr$1ua$1@mamenchi.zrz.TU-Berlin.DE>

Richard Morse  <remorse@partners.org> wrote in comp.lang.perl.misc:
> In article <cav2b6$m3n$1@mamenchi.zrz.TU-Berlin.DE>,
>  anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> > I am strongly opposed to adding stuff to code "for clarity's sake", even
> > if it provably doesn't hurt.

[...]

> As an example, I prefer the following:
> 
>    my $var = scalar(@array);
> 
> instead of:
> 
>    my $var = @array;
> 
> because it explicates that I'm interested in the size of the array -- 
> and makes it obvious that I didn't mistype the sigil in front of 'var'.

That's an error that would almost certainly be detected elsewhere under
strict.  No need for special guards against that.

> I also, on the few occasions when I use c-style loops, prefer:
> 
>    for (my $i = 0; $i < scalar(@array); $i++) {
>    }
> 
> although the reason for this doesn't spring to mind -- probably because 
> it's how I taught myself (I only discovered this forum a few months 
> back, although I have been programming in Perl for about five years now).

It's just another case of accessing the array size.  If you do one, you
practically have to do the other.

> I don't really see that either of these two cases makes it harder to 
> understand the code -- in fact, when I'm reading over it really quickly, 
> it makes it easier...

A matter of habit, I suppose.  I do have to look twice and condition my
perception to ignore the "scalar".

It also depends on the frame of reference.  Since I know you as a
trustworthy Perl programmer, I know how to read it.  Seen in isolation,
it would make me wonder if you had understood the concept of scalar
context.  In beginner's code, posted to clpm, say, I would certainly
point out that "scalar" is redundant for this reason.  A construct that
is bad in beginner's code should be avoided in advanced code unless
there is a strong reason to use it.  Is the "context clarification"
it provides a strong-enough reason?  Your call.

Context dependency is one of the very distinctive features of Perl.
No other language, except natural languages, makes use of it to quite
that extent, and it's the one feature that contributes most to making
Perl a bit like natural languages.  So here's the killer argument
against scalar() in scalar context:

It is un-natural and unperlish!

So there.

Anno


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

Date: Sat, 19 Jun 2004 05:22:59 GMT
From: "SM" <kayp511-w@yahoo.com>
Subject: Re: Can't locate package AutoLoader for @File::List::ISA at...
Message-Id: <T4QAc.1550$wY3.692@newssvr25.news.prodigy.com>

The piece of code that generates this is:

use File::List;
my $p = "c:/tools/pcb/bin";
my $search = new File::List($p);
my @S = @{ $search->find("extracta?(\.exe)?\$") };
foreach $s ( @S )
{
    print "$s \n";
}

Thansk you for the hint. I will try to use File::Find, if it works out
I will change the code

Regards,

-shahriar




"Sisyphus" <kalinaubears@iinet.net.au> wrote in message
news:40d2d88a$0$28944$5a62ac22@per-qv1-newsreader-01.iinet.net.au...
> Shahriar wrote:
> > Hi Folks,
> >
> > I just installed *FILE-LIST* from ASP. I am running ASP (see below for
> > version information)
> > does any one know about this error:
> >
> > This is perl, v5.8.3 built for MSWin32-x86-multi-thread
> > (with 8 registered patches, see perl -V for more detail)
> >
> > Copyright 1987-2003, Larry Wall
> >
> > Binary build 809 provided by ActiveState Corp.
http://www.ActiveState.com
> > ActiveState is a division of Sophos.
> > Built Feb  3 2004 00:28:51
> >
> > Regards,
> >
> > -shahriar
> >
> >
>
> The version of ActiveState perl that you're running probably has nothing
> to do with the error you're getting.
> What are you doing that's producing the error (ie what code are you
> running) ?
>
> Cheers,
> Rob
>
> -- 
> To reply by email u have to take out the u in kalinaubears.
>




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

Date: 18 Jun 2004 18:35:37 -0700
From: shalinij1@yahoo.com (Shalini Joshi)
Subject: Embedding perl in Java
Message-Id: <283d6b7e.0406181735.1b477099@posting.google.com>

Hi!

I found out about the JPL module that allows us to write perl code
within a java program and vice versa.

The reason I'd be interested in this particular thing is that we dont
want our clients to actually see the source code(i am guessing there
is no way to hide a perl script from a user and just give an
executable kind-of, since it's a script). So to actually produce a
product we thought of embedding the script in a java program and
compiling it and then the byte code could be supplied to the client.

Is this reasoning/line of thought correct? And if so, how do I go
about using jpl and designing the program?

I have gotten various helpful tips from this group and would really
appreciate help on this one too.


THanks a lot!

Regards,

Shalini


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

Date: Sat, 19 Jun 2004 06:41:40 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: float storage
Message-Id: <2jhug7F10vm4jU1@uni-berlin.de>

Also sprach ivo welch:

> hi perl gurus:  I would like to read about 1GB of floats, not doubles.
>  Does perl have the facility to designate internal storage of an array
> to be in float (4-byte), not double (8-byte) representation? 
> Otherwise, I am running out of memory...

Other than using Inline/XS as Ben suggested, you can try to go the
slightly cheaper path by using a packed string.

    sub next_float {
        # this function returns the next float
        # in some way
        ...
    }
    
    my $floats;
    while ( defined(my $f = next_float()) ) {
        $floats .= pack "f", $f;
    }

To get back at one of the floats, use a function:

    sub get_float {
        my ($floats, $idx) = @_;
        return unpack "f", substr $floats, $idx*4, 4;
    }

    my $f = get_float($floats, 0);  # returns the first one

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 18 Jun 2004 19:01:44 -0700
From: graceleeok@yahoo.com (Lee)
Subject: how to import env
Message-Id: <e80c8ec3.0406181801.8b52f84@posting.google.com>

Hello,

In perl, how to run a bash script to set up environment variables in
current process?  For example, suppose I have a bash script
setup_env.sh to set up some environ variables.   In a shell script,  I
can always say,

 . setup_env.sh
 ...other work follows.

in perl, how can I do that?  %ENV is too complicated.  I assume there
must be quite simple solution here.

Thanks!

Lee


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

Date: Sat, 19 Jun 2004 03:58:42 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: how to import env
Message-Id: <40D3B9DC.5020108@rochester.rr.com>

Lee wrote:

 ... 
> In perl, how to run a bash script to set up environment variables in
> current process?  For example, suppose I have a bash script
> setup_env.sh to set up some environ variables.   In a shell script,  I
> can always say,
> 
> . setup_env.sh
> ...other work follows.
> 
> in perl, how can I do that?  %ENV is too complicated.  I assume there
> must be quite simple solution here.


Well, %ENV is the mechanism provided for changing environment variable 
values in the process in which Perl is running.  I'm not aware there is 
any other, so the meaning of your statement "%ENV is too complicated" 
escapes me.  More complicated that some wished-for simpler (by some 
definition of simpler) but non-existent mechanism?  What is so 
complicated about:

    $ENV{environment_variable_name}='environment_variable_value';

anyway?  If you want to place it in a separate Perl program and call it, 
check out:

   perldoc -f do


 ...


> Lee

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sat, 19 Jun 2004 14:25:45 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Random letters, getting same results
Message-Id: <10a8d01p8kl1svakfn68eso68iptkv852a@4ax.com>

On Fri, 18 Jun 2004 20:25:13 -0400, LANkrypt0 <jasonp@monmouth.com>
wrote:

>./script.pl hello
>
>It then would get the length of the word hello and use that to generate 
>random letters of that amount. i.e, doiqw
>
>Then it SHOULD keep running until the word hello is matched with a one of 
>the random outputs.  The problem is that it outputs the same results, i.e
[snip]
>==+ BEGIN CODE +==
>
>#!/usr/bin/perl

the shebang line '#!/usr/bin/perl' is much like a 'BEGIN CODE' marker
that is much like a 'hello'...

[snip 33 lines of code]

>==+ END CODE +==

The '__END__' line is much (but not completely!) like a 'END CODE'
marker that is much like a 'bye'!


  #!/usr/bin/perl -l
  
  use strict;
  use warnings;
  
  my ($w,$c)=$_=shift ||
    die "Usage: $0 <word>\n";
  
  {
      s/./('a'..'z')[rand 26]/ge;
      print;
      $_ eq $w or $c++, redo;
  }
  
  print "`$w' found again in $c attempts";
  
  __END__


HTH,
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: Fri, 18 Jun 2004 22:19:29 -0400 (EDT)
From: Yiping Zhan <yzhan@andrew.cmu.edu>
Subject: remove redundant elements in an array
Message-Id: <Pine.LNX.4.58-035.0406182217200.14123@unix49.andrew.cmu.edu>

Say, @a = qw(1 2 3 1 4 5);

What is a good way to get (1 2 3 4 5)?

Thanks,

-- Newbie


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

Date: Fri, 18 Jun 2004 23:23:19 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: remove redundant elements in an array
Message-Id: <DkOAc.58782$7H1.1981160@news20.bellglobal.com>


"Yiping Zhan" <yzhan@andrew.cmu.edu> wrote in message
news:Pine.LNX.4.58-035.0406182217200.14123@unix49.andrew.cmu.edu...
> Say, @a = qw(1 2 3 1 4 5);
>
> What is a good way to get (1 2 3 4 5)?
>

Use a hash to remove the duplicates and then just sort the keys if you want
to put them back in a array:

my %unique = map { $_ => 1 } @a;

my @b = sort keys %unique;

Matt




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

Date: Sat, 19 Jun 2004 03:43:49 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: remove redundant elements in an array
Message-Id: <40D3B65F.3060200@rochester.rr.com>

Yiping Zhan wrote:

> Say, @a = qw(1 2 3 1 4 5);
> 
> What is a good way to get (1 2 3 4 5)?
 ...
> -- Newbie
> 

@b{@a}=1;@b=sort keys %b;

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sat, 19 Jun 2004 07:19:22 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: remove redundant elements in an array
Message-Id: <_NRAc.4321$Yb1.2466@nwrddc02.gnilink.net>

Yiping Zhan wrote:
> Say, @a = qw(1 2 3 1 4 5);
>
> What is a good way to get (1 2 3 4 5)?

Please see "perldoc -q duplicate" and "perldoc -q sort".

jue




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

Date: 19 Jun 2004 03:47:02 -0700
From: jamasd@hotmail.com
Subject: Re: sorting text
Message-Id: <3151a273.0406190247.3662439f@posting.google.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2jh4fqF10ihidU1@uni-berlin.de>...
> jamasd@hotmail.com wrote:
> > Right now it is printing out the entire file in one line.
> 
> ??
> 
> Please show us the *whole* program that gives that result.

Here is my fully program:

use strict;
use warnings;

my ( $buffer , @fields , $filename , %hash1 );


open(INPUT, '<', 'C:\Documents and
Settings\Owner.NOTEBOOK\Desktop\doc.txt') or
die("Can't open file \"$filename\" : $!\n");

%hash1 = ( "ytkyk" => 1 , "ghjhg" => 1 );

while ( $buffer = <INPUT> ) {
chomp $buffer;
@fields = split(/\t+/,$buffer);
next if @fields < 3;
unless ( exists $hash1{$fields[2]} ) {
next;
} print "$buffer\n";
}
close INPUT;

Now it is just printing a blank screen, which is not what i wanted. I
would like to print out:

1234123 jaesdf ytkyk 345234
1264345 ghgfdf ghjhg 657658
3456765 sdasdf ytkyk 456543
5447454 asdqfr ytkyk 254364

Note: "1231232 assffg werwe 123454" was not in the above

Thanks for you help, and sorry if I am unclear sometimes.


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

Date: 19 Jun 2004 13:03:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sorting text
Message-Id: <cb1di4$3er$1@mamenchi.zrz.TU-Berlin.DE>

 <jamasd@hotmail.com> wrote in comp.lang.perl.misc:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message
> news:<2jh4fqF10ihidU1@uni-berlin.de>...
> > jamasd@hotmail.com wrote:
> > > Right now it is printing out the entire file in one line.
> > 
> > ??
> > 
> > Please show us the *whole* program that gives that result.
> 
> Here is my fully program:

Your non-existent indentation makes it hard to read.  Please indent
your program to show the nesting of blocks.

> use strict;
> use warnings;
> 
> my ( $buffer , @fields , $filename , %hash1 );

It is better to declare variables when they are first used.

> open(INPUT, '<', 'C:\Documents and
> Settings\Owner.NOTEBOOK\Desktop\doc.txt') or
> die("Can't open file \"$filename\" : $!\n");
> 
> %hash1 = ( "ytkyk" => 1 , "ghjhg" => 1 );
> 
> while ( $buffer = <INPUT> ) {
> chomp $buffer;

Why chomp $buffer?  You are just tacking the newline on again when
printing.

> @fields = split(/\t+/,$buffer);

This is the main error.  You split on tabs, but your data, as shown in
this thread, don't contain tabs.  Split on white space for better
results.

> next if @fields < 3;

This skips all records because the split on tab has left @fields with
one element.

> unless ( exists $hash1{$fields[2]} ) {

Why a "next if ..." for the last statement, but a full-blown block if
here?  Be consistent!  Also, you have built your hash to contain true
values for the valid fields, but make no use of it here.  Another
inconsistency.

    next unless $hash1{ $fields[ 2]};

> next;
> } print "$buffer\n";

This is horrible.  Ending a block in a line and adding the first statement
*after* the block on the same line is contrary to every accepted style
of programming.  "print ..." belongs on a new line.

> }
> close INPUT;
> 
> Now it is just printing a blank screen, which is not what i wanted. I
> would like to print out:
> 
> 1234123 jaesdf ytkyk 345234
> 1264345 ghgfdf ghjhg 657658
> 3456765 sdasdf ytkyk 456543
> 5447454 asdqfr ytkyk 254364
> 
> Note: "1231232 assffg werwe 123454" was not in the above
> 
> Thanks for you help, and sorry if I am unclear sometimes.

Correct the split, and it will basically work.

Below is how I would code (and format!) it.  I have used nonsensically
named variables instead of @fields.  Use real descriptive names instead.
The check for the number of fields is equivalently replaced by a check for
definedness of one of the fields.  On the other hand, I've done away with
the variable $buffer.  The name doesn't tell the reader anything.  Other
small changes are obvious.

    my %pong_tab = (
        "ytkyk" => 1,
        "ghjhg" => 1,
    );

    while ( <DATA> ) {
        my ( $ping, $pang, $pong, $pung) = split' ';
        next unless defined $pong and $pong_tab{ $pong};
        print;
    }
 
Anno


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

Date: Sat, 19 Jun 2004 04:14:29 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Text Parsing
Message-Id: <40D3BD8F.90207@rochester.rr.com>

Shalini Joshi wrote:

 ...
> I cant seem to figure out why your code (as is) goes into an infinite
> loop when I try and run it??
> 
> My initial approach was something like this:
>      $/='FPR';
>      <>; #empty record
>      while(<>){
>       chomp;
>       print  $_ ;
> 
> 
> (Obviously it doesnt do what i want it to do..was just trying it out
> to see how it works)


Well, that code doesn't go into an infinite loop for me.  It generates a 
compile error.  Fixing that by adding the missing }, it works fine, 
assuming that what you want to do is take the lines of a text file with 
records separated by FPR and put them all on one line with no whitespace 
in between.  Are you sure the program isn't just waiting for you to 
enter records separated by FPR on standard input (which is where it will 
look for input unless you give it some filenames as arguments)?  It will 
continue to do that until you give it an end-of-file.  And note that 
your "empty record" must be separated from the next record by the 
character sequence FPR , not a newline.  And depending upon your OS and 
whether you have STDIN coming from a console, a file or something else, 
you might not get anything until the OS thinks you sent a line, using 
the OS's definition of a line (terminated by the OS's newline sequence), 
not Perl's FPR idea of a newline which you gave Perl.


 ...


> Shalini


-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

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


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