[25933] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8153 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 7 06:05:40 2005

Date: Tue, 7 Jun 2005 03:05:03 -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, 7 Jun 2005     Volume: 10 Number: 8153

Today's topics:
    Re: counting word occurances <vticau@excite.com>
        making perl act like a proxy <dfs@scomun.wpm.ws>
    Re: making perl act like a proxy <1usa@llenroc.ude.invalid>
    Re: Multilanguage capable scripts howto? <krienke@uni-koblenz.de>
    Re: Newbie question: how to browse for a file in Tk? <amheiserbush@yahoo.com.au>
    Re: random numbers <pilkowsk@informatik.uni-marburg.de>
    Re: Randomly selecting Variables <georgekinley@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 06 Jun 2005 20:48:22 GMT
From: vali <vticau@excite.com>
Subject: Re: counting word occurances
Message-Id: <qE2pe.6567$ot7.3118@news.cpqcorp.net>

A. Sinan Unur wrote:
> vali <vticau@excite.com> wrote in
> news:zs%oe.6528$7h7.4736@news.cpqcorp.net: 
> 
> [ Please quote properly. You inserted your responses in the middle of 
>   my responses, and did not delete parts you were not replying to. This
>   makes it difficult to carry on an intelligent conversation with you.
> ]

Point taken.

> 
> 
>>A. Sinan Unur wrote:
>>
>>>"John W. Krahn" <someone@example.com> wrote in
>>>news:HX2oe.31147$on1.29725@clgrps13: 
>>>
>>>
>>>
>>>>A. Sinan Unur wrote:
>>>>
>>>>
>>>>>vali <vticau@excite.com> wrote in
>>>>>news:r80oe.6452$II3.3529@news.cpqcorp.net: 
>>>
>>>...
>>>
>>>
>>>>>>Wasn't aware about the above faq. I've been using for years:
>>>>>>s/(^\s+|\s+$)//g;
>>>>>>which seems to be the same (or not ?!) as:
>>>>>>s/^\s*//; s/\s*$//;
>>>
>>>...
>>>
>>>
>>>>>sub faq {
>>>>>   my @input = @{ $INPUT };
>>>>>   for (@input) {
>>>>>       s/^\s*//;
>>>>>       s/\s*$//;
>>>>>   }
>>>>>}
>>>>
>>>>The FAQ uses \s+ instead of \s* which is more efficient.
>>>
>>>Thank you for the correction. I failed to notice the typo in vali's
>>>post. 
>>
>>Just followed up on Jurgen's one.
> 
> 
> So what?

Nothing. Or maybe another way of saying "Thank you for the correction. I 
failed to notice the typo in Jurgen's post"

> 
> 
>>>I was suprised to see just how much more efficient \s+ was compared
>>>to \s*. 
>>
>>That's what I thought when using it on my approach.
> 
> 
> Is that why you captured unnecessarily, alternated unnecessarily, used g 
> unnecessarily etc???

Nope. That (to be more precise: s/(^\s+|\s+$)//g;) was just a poor 
attempt to avoid two steps when strip any beginning/end space(s) from a 
string.

> 
> 
>>>Finally, this supports my assertion that s/(^\s+|\s+$)//g; is not the
>>>same as what the answer to the FAQ recommends.
                                   ^^^^^^^^^^^^^^
>>
>>That's right. I'll start using it (and check more often the FAQs).
                                  ^^
> 
> 
> You'll start using what?

For those that couldn't get it from the context I was referring to the 
FAQ recommendation on this regard which, to be more specific, is:
     for ($string) {
         s/^\s+//;
         s/\s+$//;
     }

Have a good and prolific day !

__Vali

> 
> Sinan


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

Date: Mon, 06 Jun 2005 11:45:23 -0700
From: df sommeheld <dfs@scomun.wpm.ws>
Subject: making perl act like a proxy
Message-Id: <4dWdna7UFLxcBDnfRVn-vw@giganews.com>

This may not be possible, and I hope I don't muck up what I want to do, 
but here goes:

we have an ssh server that is behind a corporate firewall. When users 
log in, through ssh they get forwarded to this box and then forwarded to 
another telnet connection. The problem is that if the corp firewall 
hangs up for any reason, the users not only lose their connection to 
ssh, the lose everything they were working on. After seven years, they 
still haven't learned to save their work, so I guess they never will.

My idea is to have them log in as usual, then have a script in their 
user profile fire up a telnet connection to the data server. The script 
would then act like a proxy and take commands sent over ssh and pass 
them on to the telnet connection. If the ssh session dies, the user gets 
kicked, but the telnet sessions stays alive, and when they reconnect, 
the script just puts them back into the telnet session.

This may be impossible, or it may be commonly done, I just don't know. I 
don't know how to query google in a way that will give me the right 
answer so I'm asking here. Could one of the Perl sages let me know if 
this is doable?

TIA!


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

Date: Mon, 06 Jun 2005 18:49:59 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: making perl act like a proxy
Message-Id: <Xns966D96A71E30Dasu1cornelledu@127.0.0.1>

df sommeheld <dfs@scomun.wpm.ws> wrote in news:4dWdna7UFLxcBDnfRVn-
vw@giganews.com:

> This may not be possible, and I hope I don't muck up what I want to
> do, but here goes:
> 
> we have an ssh server that is behind a corporate firewall. When users 
> log in, through ssh they get forwarded to this box and then forwarded
> to another telnet connection. The problem is that if the corp firewall 
> hangs up for any reason, the users not only lose their connection to 
> ssh, the lose everything they were working on. After seven years, they 
> still haven't learned to save their work, so I guess they never will.

You have mis-identified the solution.

<URL: http://www.kuro5hin.org/story/2004/3/9/16838/14935>

<URL: http://www.gnu.org/software/screen/>

Sinan.

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Tue, 07 Jun 2005 09:36:30 +0200
From: Rainer Krienke <krienke@uni-koblenz.de>
Subject: Re: Multilanguage capable scripts howto?
Message-Id: <d83ipu$j29$1@news.uni-koblenz.de>

A. Sinan Unur wrote:


>> <URL:
>> http://search.cpan.org/~nwclark/perl-5.8.7/lib/Locale/Maketext.pod>
> 
> Actually, you probably want:
> 
> <URL: http://search.cpan.org/~sburke/Locale-Maketext-1.09/>

Thanks for the hint. Actually I tried Locale::Maketext::Simple but without
any success. Probably I am missing something. But what?  Here is what I
tried:

The perl script t.pl:

#!/usr/bin/perl
package t;
use Locale::Maketext::Simple (
    Path => '/home/krienke/tmp/perl/auto'
);
loc_lang('de_DE'); # also tried "de" or without loc_lang
print loc("Hello");


In /home/krienke/tmp/perl/auto there is the translation file t.po and the
file t.mo created with msgfmt -o t.mo t.po. In ~krienke/tmp/perl/auto there
is also a de_DE/LC_MESSAGES subdirectory containing the same t.mo file. The
file t.po looks like this:

#  translator-comments
#. automatic-comments
#: reference...
#, flag...
msgid  "Hello"
msgstr  "Hallo"

Calling the script results in the output of "Hello" but not the german
"Hallo". The LANG env variable on my machine is de_DE@euro. I also tried to
copy the file t.mo to /usr/share/locale/de_DE/LC_MESSAGES and tried the
default package initialisation: use Locale::Maketext::Simple; instead of
the above but no change.

Can anyone help me out?

Thanks
Rainer


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

Date: Mon, 6 Jun 2005 14:11:47 -0400
From: "James Calivar" <amheiserbush@yahoo.com.au>
Subject: Re: Newbie question: how to browse for a file in Tk?
Message-Id: <d823l3$1d3$1@home.itg.ti.com>

"Ala Qumsieh" <notvalid@email.com> wrote in message
news:Ba0pe.581$Z44.347@newssvr13.news.prodigy.com...
> James Calivar wrote:
> > Hello all,
> >
> > I'm taking my first stab at writing a Tk interface for a Perl script
that I
> > have developed.  The existing Perl script reads configuration parameters
> > from a separate .ini file, and uses those values to do its thing while
> > running.  Some of these config params are pathnames and filenames on the
> > system that the script is running on.  What I'd like to be able to do is
to
> > have the user be able to browse their filesystem using the mouse, and
select
> > items that way.  However, in looking through "Learning Perl/Tk," I
didn't
> > immediately see anything that would allow me to do it, so I'm wondering
if
> > someone here could give me an idea on how such a task is accomplished in
> > Perl/Tk.
>
> You need to use getOpenFile:
>
> $top->getOpenFile(options);
>
> check out the docs for Tk::getOpenFile for more info.
>
> --Ala

Yes - I just stumbled across this on
http://www.perltk.org/articles/filedialogs/filedialogs.html.  It is exactly
what I need.  Thanks, now I do not have to mess with the 3rd party
Tk-FileDialog module (that apprently doesn't work anyway).

James




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

Date: Tue, 7 Jun 2005 01:32:59 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: random numbers
Message-Id: <3gk4nkFctrsnU1@individual.net>

* Mei schrieb:
> 
> --Thanks all. The reason that I did not use 1..10 is because the six numbers 
> must be different.

The "1..10" has almost nothing to do with your 6 numbers. "1..10" is
generating ten numbers, not six.

> 
> --Once I take off the do-until loop, you will see the result like: ¡§1 3 4 6 
> 8 10 vs 2 3 5 7 8 10¡¨. So far, this works.
> 
> -- But as you pointed out, I want to see how long would it take for me to 
> generate the sequence (2, 3, 5, 7, 8, 10). So far, I am still having 
> troubles.

You don't mention which kind of troubles you have.

> 
> ###### modified from the previous script #####
> 
> #!/usr/bin/perl -w
> # generate 6 random numbers (1~10) that match exactly to the @ticket
> # count the number of loops
> use strict;
> 
> my @ticket = sort {$a <=> $b} (2, 3, 5, 7, 8, 10);
> my $ticket = "@ticket";
> my @all_number = ();
> my @new_number = ();
> my $count = 0;
> 
> # generate 10 numbers
> for (my $i = 0; $i < 10; $i++) {
>     my $number = $i + 1;
>     push (@all_number, $number)
> }

This for loop is generating the numbers from 1 to 10 and saves them in
the array @all_number -- not more, not less. This has absolutely nothing
to do with your six different numbers you want to get afterwards. And as
Sinan has pointed out you could replace this with

    @all_number = 1 .. 10;
    
This is absolutely equivalent, but shorter -- and better to read.

> 
>       for (my $i = 0; $i < 6; $i++) {
>         my $position = int(rand(scalar(@all_number)));
>         # Pick a random number from @all_number
>         my $number = splice (@all_number, $position, 1);
>         push (@new_number, $number);
>       }

This for loop *calculates* your six random numbers. First, it gets a
random position in the array. With splice() you ask for the specified
element in your array to push it into the array @new_number. This could
be simplified to

    for ( 1 .. 6 ) {
        my $pos = int rand @all_number;   # no scalar() needed
        my $number = $all_number[ $pos ]; # no splice() needed
        push @new_number, $number;
    }
    
You could write this all in one, without saving some values in $pos and
$number. That is, what Sinan has written:

    for ( 1 .. 6 ) {
        push @new_number, $all_number[ rand @all_number ];
    }

Sure, you could use map() instead of a for loop. That is, what I've done
in my posting:

    @new_numbers = map { $all_number[ rand @all_number ] } 1 .. 6;

Remember that this are just improvements to the code you've posted. I
think, your problem is to get six *different* numbers. Neither your code
nor our improvements will do this. But Xho has told you how this could
be done with a hash:

    my %hash;
    $hash{ int rand @all_number } = 1 while keys %hash < 6;
    @new_numbers = @all_number[ keys %hash ];

Another solution is to use List::Util's shuffle algorithm and cut off a
subarray of six elements. This could be more readable, especially if
you're not so familiar with hashes.

    use List::Util qw( shuffle );
    @new_numbers = ( shuffle @all_number )[ 0 .. 5 ];

Please, try to run the following script:


    #!/usr/bin/perl -w
    use strict;
    use List::Util qw( shuffle );

    my @ticket = sort 2, 3, 5, 7, 8, 10;
    my @all = 1 .. 10;
    my $count = 0;

    while ( ++$count ) {
        # get six different elements from @all
        my @new = sort +( shuffle @all )[ 0 .. 5 ];

        # print out for debugging
        print "@ticket vs @new\n";

        # stop if @ticket and @new are equal
        last if "@ticket" eq "@new";
    }

    print $count;
    __END__


regards,
fabian


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

Date: Tue, 07 Jun 2005 08:13:32 GMT
From: "George" <georgekinley@hotmail.com>
Subject: Re: Randomly selecting Variables
Message-Id: <xn0e37q21b6gmph003@news.europe.nokia.com>

Scott Bryce wrote:

> George wrote:
> 
> > Hi,
> > I am sorry and not sure if this query is directly related to perl,
> > but since I want to do this trick in perl so
> > 
> > I have a 30 variables out of which I need to randomly select 15  and
> > then randomly equate them numbers between 01 and 90,
> > Thanks
> 
> Your problem definition is confusing. What is the significance of
> having exactly 30 variables in the pool, if you want to select 15 out
> of 90 values? Could you use a hash with 30 keys? (But why, if you
> only want to use 15 of them?)
> 
> If you want to use 15 numbers randomly selected from a pool of 90
> possible values, assign the values to 90 elements in an array,
> shuffle the array, pull the first 15 values from the shuffled array.

Those 30 vaiables are used in formating a tabular label  defined in
format function , now out of 30 only 15 are assigned in one go , very
much like bingo tickets,


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

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


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