[24421] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6607 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 25 18:06:02 2004

Date: Tue, 25 May 2004 15:05:11 -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           Tue, 25 May 2004     Volume: 10 Number: 6607

Today's topics:
    Re: Am I a programmer or a scripter? <kkeller-usenet@wombat.san-francisco.ca.us>
        CPAN.pm configuration <socyl@987jk.com>
        create directory ... <hanssonrickard@hotmail.com>
    Re: create directory ... <tim@orb.aker.com>
    Re: create directory ... <jtc@shell.dimensional.com>
    Re: create directory ... <hanssonrickard@hotmail.com>
    Re: create directory ... <hanssonrickard@hotmail.com>
    Re: create directory ... <noreply@gunnar.cc>
        From one-liner to script: -i option? <socyl@987jk.com>
        how do I convert a file into its 8 bit 0/1 pattern ? (Jack)
    Re: how do I convert a file into its 8 bit 0/1 pattern  (Anno Siegel)
    Re: how do I convert a file into its 8 bit 0/1 pattern  <nobull@mail.com>
    Re: how do I convert a file into its 8 bit 0/1 pattern  <usenet@morrow.me.uk>
    Re: how do I convert a file into its 8 bit 0/1 pattern  <krahnj@acm.org>
    Re: how to pass a hash from c (Anno Siegel)
        How to test @INC as seen by CGI script? <please_post@nomail.edu>
    Re: How to test @INC as seen by CGI script? <noreply@gunnar.cc>
    Re: Komodo as a editor? (Markus Dehmann)
    Re: Map or Regex and Sorting (Anno Siegel)
    Re: Map or Regex and Sorting <schaumfestiger@gmx.de>
        ne not working? (Jay Sun Ex)
    Re: ne not working? <glex_nospam@qwest.invalid>
    Re: ne not working? <ittyspam@yahoo.com>
    Re: ne not working? <ThomasKratz@REMOVEwebCAPS.de>
    Re: Newbie Question <ittyspam@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 25 May 2004 09:25:27 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Am I a programmer or a scripter?
Message-Id: <n1sv8c.tqc.ln@goaway.wombat.san-francisco.ca.us>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

On 2004-05-25, Mothra <mothra@mothra.com> wrote:

> So is there a real difference, or is it just semantic snobbery?

Yes.  :)

I tell people I write code, to sidestep the semantics altogether.
(Of course, I usually type it, but they know what I mean.)

- --keith

- -- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAs3N1hVcNCxZ5ID8RAoGTAJ9rED/2szBnyBPNzTRfwXKfdxASawCcDzgh
UafQSjoSpheCGqcXaiydYtE=
=eUo3
-----END PGP SIGNATURE-----


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

Date: Tue, 25 May 2004 16:38:43 +0000 (UTC)
From: kj <socyl@987jk.com>
Subject: CPAN.pm configuration
Message-Id: <c8vsqi$r3k$1@reader2.panix.com>




On my system I have Perl 5.6.1 under /usr and Perl 5.8.3 under /opt
[1].  This has broken my ability to use CPAN.pm.  More specifically,
almost invariably the "make test" step fails.  This is because the
command that runs the test script uses flags such as -I/usr/lib/perl/5.6.1,
when it should be using -I/opt/lib/perl/5.8.3, etc.  And also, even
though I bring up the CPAN shell with "/opt/bin/perl -MCPAN -e
shell", during the "make test" part the tests scripts get run with
/usr/bin/perl instead of with /opt/bin/perl (although I'm less sure
that this is the case every time).

How do I configure things such that CPAN.pm uses the Perl (executable
and libraries) that live under /opt and not the Perl under /usr?

Thanks!

kj

[1] Long story: basically, my stable-release Debian system uses
5.6.1 whenever it needs to use Perl, but I prefer to use 5.8.3;
the Perl 5.8.x distributed with Debian's testing release is compiled
with threads, which I do not want, so instead of upgrading my
system's Perl to testing, I installed 5.8.3 under /opt.
-- 
NOTE: In my address everything before the period is backwards.


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

Date: 25 May 2004 23:38:16 +0200
From: Rickard <hanssonrickard@hotmail.com>
Subject: create directory ...
Message-Id: <40b3bcc8$1@news.wineasy.se>

Hi,

I am currently setting up an Perl script which will create an directory.

That is not any problem, the problem is that how do i create an 
directory out of an variable. Hmm, like this,

my $test = "/tmp/"
my $test2 = "test"

mkpath('$test$test2), 0, 0777);

What i wan´t is to use the values of $test & $test2 to create an directory.

Is that possible?


When i try above i create an directory called $test$test2 instead of 
"/tmp/test"


I have read about it at cpan, but no info about how to do it.

//Rickard


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

Date: Tue, 25 May 2004 17:43:16 -0400
From: Tim Orbaker <tim@orb.aker.com>
Subject: Re: create directory ...
Message-Id: <yridndZ98IBoIC7d4p2dnA@wideopenwest.com>



Rickard wrote:
> Hi,
> 
> I am currently setting up an Perl script which will create an directory.
> 
> That is not any problem, the problem is that how do i create an 
> directory out of an variable. Hmm, like this,
> 
> my $test = "/tmp/"
> my $test2 = "test"
> 
> mkpath('$test$test2), 0, 0777);

I think you meant:

mkpath( '$test$test2', 0, 0777 );

Your problem is in the quotation. Items encosed in single quotes are 
literals. They are not expanded. Use double quotes...

What you need is:

mkpath( "$test$test2", 0, 0777 );



> What i wan´t is to use the values of $test & $test2 to create an directory.
> 
> Is that possible?
> 
> 
> When i try above i create an directory called $test$test2 instead of 
> "/tmp/test"
> 
> 
> I have read about it at cpan, but no info about how to do it.
> 
> //Rickard



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

Date: 25 May 2004 15:44:43 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Re: create directory ...
Message-Id: <slrncb7fig.f8k.jtc@shell.dimensional.com>

In article <40b3bcc8$1@news.wineasy.se>, Rickard wrote:
> Hi,
> 
> I am currently setting up an Perl script which will create an directory.
> 
> That is not any problem, the problem is that how do i create an 
> directory out of an variable. Hmm, like this,
> 
> my $test = "/tmp/"
> my $test2 = "test"
> 
> mkpath('$test$test2), 0, 0777);

I'm not sure what mkpath is, but I believe what you're asking for is how to
concatenate strings - so you can use the '.' operator:

mkpath($test . $test2, 0, 0777);

If you want portability, you might try using File::Spec.


> 
> What i wan´t is to use the values of $test & $test2 to create an directory.
> 
> Is that possible?
> 
> 
> When i try above i create an directory called $test$test2 instead of 
> "/tmp/test"
> 
> 
> I have read about it at cpan, but no info about how to do it.
> 
> //Rickard


-- 
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]


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

Date: 25 May 2004 23:47:37 +0200
From: Rickard <hanssonrickard@hotmail.com>
Subject: Re: create directory ...
Message-Id: <40b3bef9$1@news.wineasy.se>

Tim Orbaker wrote:

> 
> 
> Rickard wrote:
> 
>> Hi,
>>
>> I am currently setting up an Perl script which will create an directory.
>>
>> That is not any problem, the problem is that how do i create an 
>> directory out of an variable. Hmm, like this,
>>
>> my $test = "/tmp/"
>> my $test2 = "test"
>>
>> mkpath('$test$test2), 0, 0777);
> 
> 
> I think you meant:
> 
> mkpath( '$test$test2', 0, 0777 );
> 
> Your problem is in the quotation. Items encosed in single quotes are 
> literals. They are not expanded. Use double quotes...
> 
> What you need is:
> 
> mkpath( "$test$test2", 0, 0777 );
> 
> 
> 
>> What i wan´t is to use the values of $test & $test2 to create an 
>> directory.
>>
>> Is that possible?
>>
>>
>> When i try above i create an directory called $test$test2 instead of 
>> "/tmp/test"
>>
>>
>> I have read about it at cpan, but no info about how to do it.
>>
>> //Rickard
> 
> 
Then i get following:

Insecure dependency in mkdir while running wit -T switch at 
/usr/share/lib/perl5/File/Path.pm at line 133.


Should i run script without -T (perl -wT)

//Rickard


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

Date: 25 May 2004 23:53:05 +0200
From: Rickard <hanssonrickard@hotmail.com>
Subject: Re: create directory ...
Message-Id: <40b3c041$1@news.wineasy.se>

Jim Cochrane wrote:

> In article <40b3bcc8$1@news.wineasy.se>, Rickard wrote:
> 
>>Hi,
>>
>>I am currently setting up an Perl script which will create an directory.
>>
>>That is not any problem, the problem is that how do i create an 
>>directory out of an variable. Hmm, like this,
>>
>>my $test = "/tmp/"
>>my $test2 = "test"
>>
>>mkpath('$test$test2), 0, 0777);
> 
> 
> I'm not sure what mkpath is, but I believe what you're asking for is how to
> concatenate strings - so you can use the '.' operator:
> 
> mkpath($test . $test2, 0, 0777);
> 
> If you want portability, you might try using File::Spec.
> 
> 
> 
>>What i wan´t is to use the values of $test & $test2 to create an directory.
>>
>>Is that possible?
>>
>>
>>When i try above i create an directory called $test$test2 instead of 
>>"/tmp/test"
>>
>>
>>I have read about it at cpan, but no info about how to do it.
>>
>>//Rickard
> 
> 
> 
Are there any other command to use to create an directory?

The thing is that the first variable i use gets its value from an 
textfile and the second variable gets it value from an html form.

That is why i want to create an path using these two variables.

Oh, by the way, i use File::Path for the mkpath command.

//Rickard Hansson

//Rickard H


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

Date: Tue, 25 May 2004 23:57:35 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: create directory ...
Message-Id: <2hhtttFdc3v7U1@uni-berlin.de>

Rickard wrote:
> Tim Orbaker wrote:
>> What you need is:
>>
>> mkpath( "$test$test2", 0, 0777 );
>
> Then i get following:
> 
> Insecure dependency in mkdir while running wit -T switch at 
> /usr/share/lib/perl5/File/Path.pm at line 133.
> 
> Should i run script without -T (perl -wT)

If it's a CGI script, doing so would be a bad 'solution'. You'd better 
learn from

     perldoc perlsec

how to untaint tainted data.

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



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

Date: Tue, 25 May 2004 15:42:39 +0000 (UTC)
From: kj <socyl@987jk.com>
Subject: From one-liner to script: -i option?
Message-Id: <c8vphf$psq$1@reader2.panix.com>



I want to turn this "one-liner" (broken up for clarity)

  perl -i.bak -pe '                                   \
     BEGIN { $T = 8 }                                 \
     1 while s{^( *)\t}                               \
              {$1 . (" " x ($T-((length $1)%$T)))}ex' \
     some_file

into a script, but leaving the -i option (whether it is used or
not, and if so, what argument, if any, to give it) entirely up to
the user.

The simplest thing to do would be to set up the file:

  BEGIN { $ = 8 }

  # replace a tab-containing prefix with a prefix containing only
  # spaces and producing the same level of indentation 

  1 while s{^( *)\t}
           {$1 . (' ' x ($T-((length $1)%$T)))}ex

  __END__

 ...making the script executable.  The problem with this is that I
lose the -i option.  And if I invoke the script like this

  perl -p -i.bak my_script.pl some_file

 ...I end up having to repeat the mandatory "perl -p" part every time.

What's the best way to do what I'm trying to do here?  (In case it
matters, I'm using bash under Linux, and portability is not a
concern.)

TIA,

kj

P.S. BTW, is there a way to achieve the same effect with a single
s/// (or maybe s///g), without requiring a while loop?

-- 
NOTE: In my address everything before the period is backwards.


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

Date: 25 May 2004 09:26:58 -0700
From: jack_posemsky@yahoo.com (Jack)
Subject: how do I convert a file into its 8 bit 0/1 pattern ?
Message-Id: <209b7e58.0405250826.6d1c1abd@posting.google.com>

Hi,

I assume to do this I would need to:

1- read in a file and store its binary (byte) contents into an array (in increments)
2- convert the binary bytes into their 8 bit 0/1 equivalents

Does anyone happen to have the syntax to accomplish this ?

Thank you,

Jack


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

Date: 25 May 2004 16:36:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how do I convert a file into its 8 bit 0/1 pattern ?
Message-Id: <c8vslu$rov$2@mamenchi.zrz.TU-Berlin.DE>

Jack <jack_posemsky@yahoo.com> wrote in comp.lang.perl.misc:
> Hi,
> 
> I assume to do this I would need to:
> 
> 1- read in a file and store its binary (byte) contents into an array (in
> increments)
> 2- convert the binary bytes into their 8 bit 0/1 equivalents
> 
> Does anyone happen to have the syntax to accomplish this ?

The syntax is that of "open", "read" and "sprintf".

Anno


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

Date: 25 May 2004 17:47:31 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: how do I convert a file into its 8 bit 0/1 pattern ?
Message-Id: <u9iseksbbw.fsf@wcl-l.bham.ac.uk>

jack_posemsky@yahoo.com (Jack) writes:
> 
> 1- read in a file and store its binary (byte) contents into an array (in increments)
> 2- convert the binary bytes into their 8 bit 0/1 equivalents

I do not understand what you mean by this.  On a computer[1] a file
consits of bytes and those bytes consist of 8 bits.

Perhaps if you gave an example of the desired input and output?

Anyhow this smells like an XY problem.  Whatever it is that you expect
to achive by converting the file into whatever form it is that you
were trying to describe there's almost certainly a more direct
approach.

[1] Well there are exceptions but you are unlikely to be in one of
those environments.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 25 May 2004 18:58:44 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: how do I convert a file into its 8 bit 0/1 pattern ?
Message-Id: <c90514$5dp$1@wisteria.csv.warwick.ac.uk>


Quoth anno4000@lublin.zrz.tu-berlin.de (Anno Siegel):
> Jack <jack_posemsky@yahoo.com> wrote in comp.lang.perl.misc:
> > Hi,
> > 
> > I assume to do this I would need to:
> > 
> > 1- read in a file and store its binary (byte) contents into an array (in
> > increments)
> > 2- convert the binary bytes into their 8 bit 0/1 equivalents
> > 
> > Does anyone happen to have the syntax to accomplish this ?
> 
> The syntax is that of "open", "read" and "sprintf".

And, probably, unpack.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Tue, 25 May 2004 19:31:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how do I convert a file into its 8 bit 0/1 pattern ?
Message-Id: <40B39F17.15E6F6DC@acm.org>

Jack wrote:
> 
> Subject: how do I convert a file into its 8 bit 0/1 pattern ?

perl -pe'$_=unpack"B*",$_' yourfile


John
-- 
use Perl;
program
fulfillment


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

Date: 25 May 2004 16:48:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to pass a hash from c
Message-Id: <c8vtck$rov$3@mamenchi.zrz.TU-Berlin.DE>

wwwww  <www.@o> wrote in comp.lang.perl.misc:
> hi !
> 
> i would like to use perl as a script-language for my c/c++ written programm.
> 
> i can perfectly call function with scalars.
> but how can i pass hashes (HV*) ?

That's in perlguts.  It is also in _Embedding and Extending Perl_ by
Simon Cozens & alt (from memory, books have a way of being where you
aren't).

Anno


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

Date: Tue, 25 May 2004 17:19:04 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: How to test @INC as seen by CGI script?
Message-Id: <c8vv68$ruc$1@reader2.panix.com>




Is there a simple way to test the @INC seen by one's CGI script,
other than writing a CGI script that serves @INC out on a page,
and visiting that page with a browser?

Thank you very much,

	-bill



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

Date: Tue, 25 May 2004 23:45:30 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to test @INC as seen by CGI script?
Message-Id: <2hht77Fd0ju6U1@uni-berlin.de>

bill wrote:
> Is there a simple way to test the @INC seen by one's CGI script, 
> other than writing a CGI script that serves @INC out on a page, and
> visiting that page with a browser?

Not sure what you mean ... You can of course have a CGI script print it:

     #!/usr/bin/perl
     print "Content-type: text/plain\n\n";
     print "$_\n" for @INC;

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



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

Date: 25 May 2004 13:05:06 -0700
From: markus.cl@gmx.de (Markus Dehmann)
Subject: Re: Komodo as a editor?
Message-Id: <c1e48b51.0405251205.31ea941c@posting.google.com>

Robert <catcher@linuxmail.org> wrote in message news:<hJGdnQRF9eMnhAXdRVn-jw@adelphia.com>...
> I am evaluating Komodo as an editor for work. I am doing a lot of Perl 
> work as a sysadmin and am starting to get into Perl/Tk as well. We use 
> PVCS for version control and I see Komodo integrates with that.
> 
> All that to say "Do you use it and what do you think about it?".

You should give eclipse a try. It's free, very powerful and has a nice
Perl plugin, called epic (http://e-p-i-c.sourceforge.net/), with
automatic completion, real-time error messages (while you type) etc.

Download eclipse 2.1.2. Then install the perl plugin via the update
manager, with http://e-p-i-c.sourceforge.net/updates (or Eclipse 3.0M8
with the epic 3.0 patch).

Andi

PS: Eclipse does not support PVCS, but why not use CVS or subversion?


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

Date: 25 May 2004 16:31:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Map or Regex and Sorting
Message-Id: <c8vscl$rov$1@mamenchi.zrz.TU-Berlin.DE>

Herr Hardy  <schaumfestiger@gmx.de> wrote in comp.lang.perl.misc:
> On 24 May 2004 19:25:08 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
> Siegel) wrote:
> 
> >> __DATA__
> >> SBruhrtal32PER09CLSD
> >> SBsorpe31PER19IN18last
> >> RBruhrII33PER11OPEN
> >> RBruhrI34PER14CLSD
> >> RBharkortI40PER09OPEN
> >> RBruhrI34PER14OPEN
> >
> >That can be done using a Schwartz transform.  Assign numeric sort keys
> >to the lines.  Make the key -1 if the line contains "OPEN", otherwise
> >use the first group of digits.  Sort according to keys, throw the
> >keys away.  
> >
> >    print for                                   # print result
> >    map $_->[ 0],                               # throw keys away
> >    sort { $a->[ 1] <=> $b->[ 1] }              # sort by key
> >    map [ $_ , /OPEN/ ? -1 : ( /(\d+)/ )[ 0] ], # assign keys
> >    <DATA>;
> 
> ... buuuuut the result ist
> 
> RBruhrII33PER11OPEN
> RBharkortI40PER09OPEN
> RBruhrI34PER14OPEN
> SBsorpe31PER19IN18last
> SBruhrtal32PER09CLSD
> RBruhrI34PER14CLSD
> 
> 3 OPEN on top, rest follows, but the OPEN-values should then be
> ordered after their (\d{1,3})'s and here's 33 40 34, 
> should be 33 34 40

You weren't too clear about the sort criteria, I'm not the only one who
misunderstood.

> So, is there a way to alter the keys by 2nd mapping? 
> 
> map [ $_ , /OPEN/?$_->[0]+=1000:(0) [ 0] ],  # alter keys on 1st level
>
> but that's not referencing, I see.

Hmm...

You want to subtract, not add 1000 to bring the lines up.

Otherwise, your code makes little sense.  Since you give no context,
I must guess where you want this to appear in the map/sort pipeline.
If "2nd mapping" means what I think it means, at this point $_ is
the two-element array(ref) created in the first step.  You don't
want to match against that, nor put it in another two-element array.
You could modify the keys in a second step, I guess, but it ain't pretty.
Do it right in the first step:

    map [ $_, ( /(\d+)/)[ 0] - 1000 * /OPEN/ ], <DATA>;

 ...though that's a little exotic (and untested).

The whole approach is rather fragile, depending as it does on the
particular range 0 .. 999 for the numbers.  (Using -1 for /OPEN/ is
in the same category.)  Both try to squeeze two sort criteria
in a single key.  A two-key sort is more robust:

    print for
    map $_->[ 0],
    sort { $b->[ 1] <=> $a->[ 1] or $a->[ 2] <=> $b->[ 2] }
    map [ $_ , scalar /OPEN/, /(\d+)/ ],
    <DATA>;

Note the reverse sort on the /OPEN/ key.  Also, if other numeric
fields enter the equation some day, just add /g to the regex:
/(\d+)/g, and they will be available for the sort.

Anno


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

Date: Tue, 25 May 2004 20:16:09 +0200
From: Herr Hardy <schaumfestiger@gmx.de>
Subject: Re: Map or Regex and Sorting
Message-Id: <vj17b0d8ps99g3ceaqf8g3g2ske5odgsk2@4ax.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote on 25 May 2004
16:31:17 GMT:

>Herr Hardy  <schaumfestiger@gmx.de> wrote in comp.lang.perl.misc:
>
>> 3 OPEN on top, rest follows, but the OPEN-values should then be
>> ordered after their (\d{1,3})'s and here's 33 40 34, 
>> should be 33 34 40
>
>You weren't too clear about the sort criteria, I'm not the only one who
>misunderstood.
Sorry, Anno, I wouldn't like to waste your time.


>> map [ $_ , /OPEN/?$_->[0]+=1000:(0) [ 0] ],  # alter keys on 1st level

>You want to subtract, not add 1000 to bring the lines up.
Yes.

>Otherwise, your code makes little sense.  Since you give no context,
>I must guess where you want this to appear in the map/sort pipeline.
>If "2nd mapping" means what I think it means, at this point $_ is
>the two-element array(ref) created in the first step.  You don't
>want to match against that, nor put it in another two-element array.
>You could modify the keys in a second step, I guess, but it ain't pretty.
>Do it right in the first step:
Well, I would ask, any idea?

>    map [ $_, ( /(\d+)/)[ 0] - 1000 * /OPEN/ ], <DATA>;
That's it, exactly. I meant: somehow alter the '\d+'-value depending
on the OPEN-String, so the key is one for both,

>...though that's a little exotic (and untested).
it works.

print $_->[1]."\n" for                      # print key
sort { $a->[ 1] <=> $b->[ 1] }              # sort
map [ $_, ( /(\d+)/)[ 0] - 1000 * /OPEN/ ], # assign key
<DATA>;

__DATA__
SBruhrtal31PER09CLSD
SBsorpe33PER19IN18last
RBruhrII32PER11OPEN
RBruhrII34PER11OPEN
RBruhrI35PER14CLSD
RBharkortI36PER09OPEN

PRINTS
-968
-966
-964
31
33
35

>
>The whole approach is rather fragile, depending as it does on the
>particular range 0 .. 999 for the numbers.  (Using -1 for /OPEN/ is
>in the same category.)  Both try to squeeze two sort criteria
>in a single key.  A two-key sort is more robust:
>
>    print for
>    map $_->[ 0],
>    sort { $b->[ 1] <=> $a->[ 1] or $a->[ 2] <=> $b->[ 2] }
>    map [ $_ , scalar /OPEN/, /(\d+)/ ],
>    <DATA>;
>
>Note the reverse sort on the /OPEN/ key.  Also, if other numeric
>fields enter the equation some day, just add /g to the regex:
>/(\d+)/g, and they will be available for the sort.

print $_->[1]." - ".$_->[2]."\n" for
sort { $b->[ 1] <=> $a->[ 1] or $a->[ 2] <=> $b->[ 2] }
map [ $_ , scalar /OPEN/, /(\d+)/ ],
<DATA>;

PRINTS
1 - 32
1 - 34
1 - 36
 - 31
 - 33
 - 35
 ... and I understand what's happening.

Thank you,
Hardy


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

Date: 25 May 2004 11:03:56 -0700
From: nefarious_6x3@yahoo.co.uk (Jay Sun Ex)
Subject: ne not working?
Message-Id: <135fa1e0.0405251003.61dd86f7@posting.google.com>

I searched thru the posts for something on ne and didn't come across
anything that could explain what my script is not doing. I am just
doing a simple test. If I change the "ne" to "eq" and run the program
with the same inputs it works fine, change them back to "ne" and it
doesn't work. The source is below. I am hoping it is something
insanely complicated so that I don't feel retarded. It should also be
mentioned that if I take out the || and the second inequality, ne does
what it is supposed to. I also tried substituting "or" for "||" and
have the same results. Thanks.

#!/usr/local/bin/perl -w

print "\nPlease enter your name: ";
chomp ($name = <STDIN>);
if ($name ne "me" || $name ne "myself") {
  die "\nYou're not allowed here $name. Bye!\n";
} else {
  print "\nWelcome $name\n";
}


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

Date: Tue, 25 May 2004 13:21:45 -0500
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: ne not working?
Message-Id: <Z8Msc.35$c93.41630@news.uswest.net>

Jay Sun Ex wrote:
> I searched thru the posts for something on ne and didn't come across
> anything that could explain what my script is not doing. I am just
> doing a simple test. If I change the "ne" to "eq" and run the program
> with the same inputs it works fine, change them back to "ne" and it
> doesn't work. The source is below. I am hoping it is something
> insanely complicated so that I don't feel retarded. It should also be
> mentioned that if I take out the || and the second inequality, ne does
> what it is supposed to. I also tried substituting "or" for "||" and
> have the same results. Thanks.
> 
> #!/usr/local/bin/perl -w
> 
> print "\nPlease enter your name: ";
> chomp ($name = <STDIN>);
> if ($name ne "me" || $name ne "myself") {
>   die "\nYou're not allowed here $name. Bye!\n";
> } else {
>   print "\nWelcome $name\n";
> }

If you enter 'me', then the second or (||) is true, it's not 'myself' 
('me' ne 'myself'). The or operator defines 0 or 1 as 1.

Get a little more aquainted with logical operators:

perldoc perlop

You probably want the "and" (&&) operator.

if ($name ne 'me' && $name ne 'myself') {
	print "it's not 'me' or 'myself', it could be 'I'\n";
}


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

Date: Tue, 25 May 2004 14:22:33 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: ne not working?
Message-Id: <20040525141824.R3804@dishwasher.cs.rpi.edu>

On Tue, 25 May 2004, Jay Sun Ex wrote:

> I searched thru the posts for something on ne and didn't come across
> anything that could explain what my script is not doing. I am just
> doing a simple test. If I change the "ne" to "eq" and run the program
> with the same inputs it works fine, change them back to "ne" and it
> doesn't work. The source is below. I am hoping it is something
> insanely complicated so that I don't feel retarded. It should also be
> mentioned that if I take out the || and the second inequality, ne does
> what it is supposed to. I also tried substituting "or" for "||" and
> have the same results. Thanks.
>
> #!/usr/local/bin/perl -w
>
> print "\nPlease enter your name: ";
> chomp ($name = <STDIN>);
> if ($name ne "me" || $name ne "myself") {
>   die "\nYou're not allowed here $name. Bye!\n";
> } else {
>   print "\nWelcome $name\n";
> }

You need a refresher course on first order logic.  Specifically, the bit
about only one part of a Disjunction (ie, an 'or') needing to be true for
the whole thing to be true.

Case 1: $name = 'me'
	$name ne "me" ==> false
	$name ne "myself" ==> true
	therefore, ($name ne "me" || $name ne "myself") ==> true

Case 2: $name = 'myself'
	$name ne "me" ==> true
        $name ne "myself" ==> false
        therefore, ($name ne "me" || $name ne "myself") ==> true

Case 3: $name = 'foobar'
	$name ne "me" ==> true
	$name ne "myself" ==> true
	therefore, ($name ne "me" || $name ne "myself") ==> true

There is no case which would allow your condition to be false.

You want && instead of ||

Paul Lalli


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

Date: Tue, 25 May 2004 20:34:03 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: ne not working?
Message-Id: <40b3931f.0@juno.wiesbaden.netsurf.de>

Jay Sun Ex wrote:

> I searched thru the posts for something on ne and didn't come across
> anything that could explain what my script is not doing. I am just
> doing a simple test. If I change the "ne" to "eq" and run the program
> with the same inputs it works fine, change them back to "ne" and it
> doesn't work. The source is below. I am hoping it is something
> insanely complicated so that I don't feel retarded. It should also be
> mentioned that if I take out the || and the second inequality, ne does
> what it is supposed to. I also tried substituting "or" for "||" and
> have the same results. Thanks.
> 
> #!/usr/local/bin/perl -w
> 
> print "\nPlease enter your name: ";
> chomp ($name = <STDIN>);
> if ($name ne "me" || $name ne "myself") {
>   die "\nYou're not allowed here $name. Bye!\n";
> } else {
>   print "\nWelcome $name\n";
> }

In addition to the logic problem others pointed out, it is better to use a 
lookup hash for this kind of work:

use strict;
use warnings;

my %allowed = map { $_ => undef } qw/
    me myself
/;

print "\nPlease enter your name: ";
chomp ($name = <STDIN>);

if ( exists(allowed{$name}) ) {
    print "\nWelcome $name\n";
} else {
    die "\nYou're not allowed here $name. Bye!\n";
}

Thomas

-- 
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</  #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..


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

Date: Tue, 25 May 2004 11:10:08 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Newbie Question
Message-Id: <20040525110616.U3804@dishwasher.cs.rpi.edu>

On Tue, 25 May 2004, Laurence Breeze wrote:

> I have a reference to a 2 dimensional array and I'd like to print out
> the contents of the array.  However, the number of elements will vary
> and I can't see a way of doing this.
>
> Any help or references would be appreciated.
>

Assuming for the moment this is for an actual purpose, rather than
debugging like all those who told you to use Dumper have assumed...

Why do you think it matters how many elements are in each of the nested
arrays?  The way you phrase that makes it sound like you think the only
way to loop through an array in Perl is with the C-style for loop:

for ($i=0; $i<@array; $i++ )  {
   print $array[$i]
}

You are aware, of course, that Perl provides another kind of for loop,
which is wholly independent of the size of the array over which you are
iterating, correct?

That clue should point you in the right direction.  If it doesn't, let us
know.

Paul Lalli


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

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


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