[23109] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5330 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 7 14:10:46 2003

Date: Thu, 7 Aug 2003 11:10: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           Thu, 7 Aug 2003     Volume: 10 Number: 5330

Today's topics:
        sort question <a@b.c>
    Re: sort question <noreply@gunnar.cc>
    Re: sort question <tzz@lifelogs.com>
    Re: sort question <tzz@lifelogs.com>
    Re: ssh and Perl <nospam@please.com>
    Re: tr/// question (James E Keenan)
    Re: Using slices with 'my' to initialize hash keys and  <pinyaj@rpi.edu>
    Re: using tr and ascii value (Dan Guzman)
    Re: What do you think of my first "JAPH"? (Tad McClellan)
    Re: Win32::ODBC and creating fields <levin.spambox@telia.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 07 Aug 2003 18:32:03 +0200
From: ZZT <a@b.c>
Subject: sort question
Message-Id: <bgtuu4$1bk$1@news1.wdf.sap-ag.de>

Hello perl-gurus,

I have values like this to sort:

FFDD-DDD

while FF is a fix charactervalue (fix for all values to sort) and D are 
digits, so for instance:

AB03-238
AB01-212
AB03-002

Now I would like to sort in a way that DD and DDD are joined and treated 
as a 5 digit numeric value, so the sort list should look like:

AB01-212
AB03-002
AB03-238


Can you help me a little bit?

thank you!



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

Date: Thu, 07 Aug 2003 18:46:10 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: sort question
Message-Id: <bgu0l3$sjtcr$1@ID-184292.news.uni-berlin.de>

ZZT wrote:
> I have values like this to sort:
> 
> FFDD-DDD
> 
> while FF is a fix charactervalue (fix for all values to sort) and D
> are digits, so for instance:
> 
> AB03-238
> AB01-212
> AB03-002
> 
> Now I would like to sort in a way that DD and DDD are joined and
> treated as a 5 digit numeric value, so the sort list should look
> like:
> 
> AB01-212
> AB03-002
> AB03-238

You don't need to do anything special at all; a simple lexical sort
should give you what you want:

     @unsorted = qw/AB03-238 AB01-212 AB03-002/;
     @sorted = sort @unsorted;

http://www.perldoc.com/perl5.8.0/pod/func/sort.html

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



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

Date: Thu, 07 Aug 2003 13:03:53 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: sort question
Message-Id: <4nisp9z9fq.fsf@lockgroove.bwh.harvard.edu>

On Thu, 07 Aug 2003, a@b.c wrote:
> I have values like this to sort:
> 
> FFDD-DDD
> 
> while FF is a fix charactervalue (fix for all values to sort) and D
> are digits, so for instance:
> 
> AB03-238
> AB01-212
> AB03-002
> 
> Now I would like to sort in a way that DD and DDD are joined and
> treated as a 5 digit numeric value, so the sort list should look
> like:
> 
> AB01-212
> AB03-002
> AB03-238

1) remove the 'AB' and the '-'

s/^AB// foreach @data; # could be more efficient with substr()
s/-// foreach @data;   # could be more efficient with tr()

 ...or...

s/^AB(\d\d)-(\d\d\d)/\1\2/; # 6 one way, half dozen the other

2) sort numerically (note that all values are now numbers)

@sorted_data = sort { $a <=> $b } @data;

3) reassemble your data

s/(\d\d)(\d\d\d)/AB\1-\2/ foreach @data;

There are many other ways of doing this.

Ted


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

Date: Thu, 07 Aug 2003 13:05:30 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: sort question
Message-Id: <4nekzxz9d1.fsf@lockgroove.bwh.harvard.edu>

On Thu, 07 Aug 2003, noreply@gunnar.cc wrote:
> ZZT wrote:
>> I have values like this to sort:
>> FFDD-DDD
>> while FF is a fix charactervalue (fix for all values to sort) and D
>> are digits, so for instance:
>> AB03-238
>> AB01-212
>> AB03-002
>> Now I would like to sort in a way that DD and DDD are joined and
>> treated as a 5 digit numeric value, so the sort list should look
>> like:
>> AB01-212
>> AB03-002
>> AB03-238
> 
> You don't need to do anything special at all; a simple lexical sort
> should give you what you want:
> 
>      @unsorted = qw/AB03-238 AB01-212 AB03-002/;
>      @sorted = sort @unsorted;
> 
> http://www.perldoc.com/perl5.8.0/pod/func/sort.html

You're right, I forgot the numbers were fixed length and started doing
a general numeric sort.  Disregard my followup :)

Ted


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

Date: Thu, 07 Aug 2003 14:25:57 GMT
From: Gunter Schelfhout <nospam@please.com>
Subject: Re: ssh and Perl
Message-Id: <VjtYa.53522$F92.5720@afrodite.telenet-ops.be>

Mothra wrote:

>>> I'm trying to execute a small Perl-script via ssh like this:
>>> ssh <target_pc> perl -e ' print "hello\n" '
>>> 
>>> But this doesn't seem to work.
>>> 
>>> Someone who has an idea?
>> 
>> Okay, the most obvious one:
>> 1. What makes you think this belongs in a Perl newsgroup?

See below.

>> Others to think about before you ask on a more relevant newsgroup:
>> 2. Is the SSH connections actually working?

Duh.

>> 3. Is Perl installed on the remote machine?

Duh Duh.

> Come on, that's a bit harsh.  He was trying to run some simple Perl code
> - that's obviously why he thought it was suitable for a Perl newsgroup.
> You've got to start somewhere.

Well, the thing I was trying to accomplisch was not just some simple Perl code. Well, IMHO.
I made some classes which interact and I have to run a script via eval on a remote machine. Like this:
 my $command = q( perl -e "'
                               my %checks; 
                              \$checks{group} = getgrnam fwcomposer;
                              \$checks{user} = getpwnam fwcomposer;
                              \$checks{ssh_dir} = grep { \$_ =~ m#^/etc/fwcomposer/\.ssh\$# } 
                                                                                                        glob(\"/etc/fwcomposer/.*\");
                              \$checks{ssh_keys} = grep { \$_ =~ m#^/etc/fwcomposer/\.ssh/fwcomposer.pub\$# } 
                                                                                                        glob(\"/etc/fwcomposer/.ssh/*\");
                              print join / /, %checks;
                              '");
$ret_val = $conn->command($command);

I didn't received any output, not even an error message. So I guessed (wrongly) that it was 
the interpreter that didn't give any output to the remote shell, due to the lack of errors.
Apparently, I guessed wrong.

> Someone on comp.security.ssh might just as likely have knocked him back to
> this group anyway, telling him it's not an SSH issue.
> 
> Or maybe he simply believed the hype about Perl coders all being
> friendly & helpful? ;-)

I'm also believing that there are some idiots out there who like bashing.

At least Sam gave a solution and a clue that it was indeed SSH who was responsible
for my trouble.
-- 
Blood, sweat & tears


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

Date: 7 Aug 2003 06:36:39 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: tr/// question
Message-Id: <b955da04.0308070536.a292f9d@posting.google.com>

"Sunil" <sunil_franklin@hotmail.com> wrote in message news:<aQmYa.1$ij7.65@news.oracle.com>...
> All,
>     Is it possible to use tr  to change all occurrences of  '  (single
> quote) into '' (two single quotes).

No.  Try out the following code, uncommenting 1 line at a time, and
you'll see the variants.

    use warnings;
    use strict;
    
    while (<DATA>) {
    	chomp;
    	$_ =~ tr/'/''/;
    #	$_ =~ tr/'/'X/;
    #	$_ =~ tr/'/"/;
    	print "$_\n";
    }
    
    
    
    __DATA__
    'A line with single quotes.'
    ''A line with double quotes typed individually.''
    A line with someone's apostrophe.
    A line of Perl code:  print '$var:  ', "$var\n";> 

>     I need to change all occurrences of  ' in a file to  ''
> 
Think carefully before you do this.  In English test a single quote
can be either a quote or an apostrophe -- two different semantic
results.  If the file you're altering contains computer code, single
quotes and double quotes usually have different effects.  HTH

Jim Keenan


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

Date: Thu, 7 Aug 2003 10:55:18 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Using slices with 'my' to initialize hash keys and values.
Message-Id: <Pine.SGI.3.96.1030807105252.496646B-100000@vcmr-64.server.rpi.edu>

On Wed, 6 Aug 2003, David Oswald wrote:

>my %translation;
>
>@translation {"A" .. "Z", 0 .. 9, ",", "?", "."} =
> qw/.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-..
> -- -. --- .--. --.- .-. ... - ..- ...- .-- -..-
> -.-- --.. ----- .---- ..--- ...-- ....- ..... -....
> --... ---.. ----. --..-- ..--.. .-.-.-/;
>
>Now I would like to tighten the code just a little.  In particular, it seems
>un-Perlish to not be able to declare the hash and assign its key/value pairs
>all in one statement.

Well, the problem is you can't declare a hash AND define a slice of it at
the same time.  The best I can do for you is:

  @$_{...keys...} = (...values...) for \my %hash;

-- 
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: 7 Aug 2003 08:27:31 -0700
From: dan@danguzman.com (Dan Guzman)
Subject: Re: using tr and ascii value
Message-Id: <ddf15003.0308070727.4a8f32e1@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbj3gf7.2e2.tadmc@magna.augustmail.com>...
> Dan Guzman <dan@danguzman.com> wrote:
> 
> > I'm updating a process that reads in text file from a mainframe
> > extract.  
> 
> 
> What OS is your Perl program running on?
> 
The OS is Windows 2000. Running ActivePerl build 626
> 
> > I'm having a problem when the mainframe put
> > in a certain character ' ' the perl script stops running.
> 
I've tried the suggestions above, but without success:

	$mLine =~ tr/\x1a/ /;
	$mLine =~ tr/\032/ /;	

> 
> If your program is running on an OS whose filesystem makes
> a distinction between "text" and "binary" files (like Windows),
> then:
Do you mean when the file gets picked up?  

  $ftp->login($_user,$_passw);
  $ftp->ascii();


> 
>    perldoc -f binmode
> 
> might fix it.

Would I do the binmode when I read the file?  Thanks,

Dan


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

Date: Thu, 7 Aug 2003 09:52:16 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What do you think of my first "JAPH"?
Message-Id: <slrnbj4pt0.3qk.tadmc@magna.augustmail.com>

David Oswald <spamblock@junkmail.com> wrote:

> figure out how to do it in a more compact,

> perl -e 'my %rt; @rt{qw/.- -... -.-. -.. . ..-. --. .... .. .--- -.-
> .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. .-.-.- |
> !/}=("A".."Z","."," ","\n"); for(split /\s+/,".--- ..- ... - | .- -. --- -
> .... . .-. | .--. .  .-. .-.. | .... .- -.-. -.- . .-. .-.-.- !"){print
> $rt{$_};}'
         ^
         ^

You can save several strokes.

The semicolon on the last statement in a block is optional, lose it.

  print $rt{$_} for split...

save 4 more strokes, 2 parens and 2 curlies.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 07 Aug 2003 14:47:13 GMT
From: Bernt Levinsson <levin.spambox@telia.com>
Subject: Re: Win32::ODBC and creating fields
Message-Id: <1hp4jvs4ieshccvolq3bnj4uqph4maqc5l@4ax.com>

On 6 Aug 2003 23:49:42 -0700, gnarred@yahoo.com (gnarred) wrote:

>Create fields? That's what INSERT INTO is for. 
>
>What you probably mean is create tables. I suggest you lookup the
>CREATE TABLE syntax in the documentation of whatever database system
>you're using. This is really more of an SQL question than a perl

So this can be done with SQL statemenst, great, thanks!
I'll google how to create tables with sql.



http://w1.321.telia.com/~u32102551/


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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