[30873] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2118 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 12 18:09:50 2009

Date: Mon, 12 Jan 2009 15:09:13 -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           Mon, 12 Jan 2009     Volume: 11 Number: 2118

Today's topics:
    Re: A screen like utility? <andrex@deadspam.com>
    Re: A screen like utility? <jimktrains@gmail.com>
    Re: Arrays instead of files into hashes <tim@burlyhost.com>
    Re: Arrays instead of files into hashes <tim@burlyhost.com>
    Re: Arrays instead of files into hashes <glex_no-spam@qwest-spam-no.invalid>
    Re: Arrays instead of files into hashes sln@netherlands.com
        Circular lists - 26 letters sln@netherlands.com
    Re: Circular lists - 26 letters <smallpond@juno.com>
    Re: Circular lists - 26 letters <jimsgibson@gmail.com>
    Re: Help: Cannot acquire data by split <tim@burlyhost.com>
    Re: Help: Cannot acquire data by split sln@netherlands.com
    Re: Help: Cannot acquire data by split sln@netherlands.com
    Re: Help: Cannot acquire data by split <tim@burlyhost.com>
    Re: Help: Cannot acquire data by split sln@netherlands.com
    Re: Help: Cannot acquire data by split sln@netherlands.com
    Re: Help: Cannot acquire data by split <tim@burlyhost.com>
    Re: how to encrypt password stored in ftp script <tim@burlyhost.com>
    Re: opening a file <george@example.invalid>
    Re: opening a file <jimsgibson@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 12 Jan 2009 19:51:06 GMT
From: Andrew Schulman <andrex@deadspam.com>
Subject: Re: A screen like utility?
Message-Id: <mn7nm49frs97smdoam75gvkk028134ontt@4ax.com>

> I have an application that receives output from multiple hosts and
> would like some sane way to organize the outputs.  I was thinking that
> some sort of "tabbing" system akin to  screen would work, but am not
> sure an easy way to implement that.  There is Term::Screen and I could
> do it by hand, but i don't want to recreate the wheel, if possible.
> Any other ideas are also welcome.

multitail does this, if you could arrange to pipe the output of your several
processes to it.

--
To reply by email, change "deadspam.com" to "alumni.utexas.net"


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

Date: Mon, 12 Jan 2009 14:03:15 -0800 (PST)
From: jk <jimktrains@gmail.com>
Subject: Re: A screen like utility?
Message-Id: <a56245ff-f81d-4e15-a570-f3fd964ba1ae@f20g2000yqg.googlegroups.com>

> multitail does this, if you could arrange to pipe the output of your several
> processes to it.
I'll have to look into that, but won't I have to create a fifo for
each process since it takes the files from the command line (I don't
know how to have multiple pipes open to a program like that)?  I was
also hoping for a mostly standard option (I know Term::Screen isn't,
but i can pas the pm with my program).

Jim


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

Date: Mon, 12 Jan 2009 12:22:42 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Arrays instead of files into hashes
Message-Id: <oENal.45230$%o3.1812@newsfe02.iad>

Francois Massion wrote:

> I have code which compares 2 lists of words and churns out the
> difference. So far I have done this by reading the content of files
> into a hash, but I would like to use 2 arrays, says @array1 and
> @array2 instead of files a.txt and b.txt.
> 
> I haven't managed to do this successfuly. Any suggestions? Her the
> functioning code with the files:


The idea of using hashes instead of arrays, is better, why do you want
to change it to arrays?  You mean arrays to hold the data that is
usually located in the {a,b}.txt files?  Where is that information
being generated from where you could have the data saved into an array,
or are you asking if you can take the data from the files and put them
into arrays?  Either way, you shou;dn't want to do that.  If you are
using data generated from somewhere, then add that new value to a hash
and see if it exists are you receive the data.

There's no reason to use an array first.  If you want to take the data
from the files, just do what you originally were wanting to do, and use
a hash, too.  Or do you mean that you want to save the final, unique
values into an array, after you've compared using a hash solution? 
Also, you mentioned you wanted to use arrays, but it's not working, so
can you show the code you're trying to use with arrays and what you
expect and what's not working?  Sorry, I'm a little confused by what
you're trying to accomplish, so please elaborate.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Mon, 12 Jan 2009 12:23:56 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Arrays instead of files into hashes
Message-Id: <wFNal.45231$%o3.20195@newsfe02.iad>

Tim Greer wrote:

> and see if it exists are you receive the data.
^^^^^^^^^^

"as you receive the data"
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Mon, 12 Jan 2009 15:35:54 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Arrays instead of files into hashes
Message-Id: <496bb7ba$0$89873$815e3792@news.qwest.net>

Francois Massion wrote:
> I have code which compares 2 lists of words and churns out the
> difference. So far I have done this by reading the content of files
> into a hash, but I would like to use 2 arrays, says @array1 and
> @array2 instead of files a.txt and b.txt.
> 
> I haven't managed to do this successfuly. Any suggestions? Her the
> functioning code with the files:
> 
> #!/usr/bin/perl -w
> use warnings; use strict;
> use utf8; #
> binmode STDIN,  ":utf8"; # input
> binmode STDOUT, ":utf8"; # output
> 
> my %list2;
> open(WORDLIST2,'C:\temp\b.txt') or
>     die("cannot open 'C:\temp\b.txt' because $! !\n");
> while (<WORDLIST2>) {
>     $list2{$_}=1; #or any other value
> }
> open(WORDLIST1,'C:\temp\a.txt') or
>     die("cannot open file1 because $! !\n");
> while (<WORDLIST1>){
>    print  unless exists($list2{$_});
> }

If you already have @array1, you could do the following to
create a hash that has the unique values from @array1.

my %list2 = map { $_ => 1 } @array1;

See also: perldoc -q "How do I compute the difference of two arrays"


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

Date: Mon, 12 Jan 2009 21:56:39 GMT
From: sln@netherlands.com
Subject: Re: Arrays instead of files into hashes
Message-Id: <jjenm49fm8bhu8arn72n2bk7c37phe72sv@4ax.com>

On Mon, 12 Jan 2009 10:53:23 -0800 (PST), Francois Massion <massion@gmx.de> wrote:

>I have code which compares 2 lists of words and churns out the
>difference. So far I have done this by reading the content of files
>into a hash, but I would like to use 2 arrays, says @array1 and
>@array2 instead of files a.txt and b.txt.
>
>I haven't managed to do this successfuly. Any suggestions? Her the
>functioning code with the files:
>
>#!/usr/bin/perl -w
>use warnings; use strict;
>use utf8; #
>binmode STDIN,  ":utf8"; # input
>binmode STDOUT, ":utf8"; # output
>
>my %list2;
>open(WORDLIST2,'C:\temp\b.txt') or
>    die("cannot open 'C:\temp\b.txt' because $! !\n");
>while (<WORDLIST2>) {
>    $list2{$_}=1; #or any other value
>}
>open(WORDLIST1,'C:\temp\a.txt') or
>    die("cannot open file1 because $! !\n");
>while (<WORDLIST1>){
>   print  unless exists($list2{$_});
>}

This some real old code. True beginner code.
It resolves into the common elements of two arrays.
I know your looking for the difference but you could
extrapolate difference from common. It works for what I
use it for, merging directories, renaming dups.

If you want the whole program for usage exampl just say so.
Good luck!

sln

#######################################################
# Get Common Elements (from two N-dimensioned Array's)
# IN  - Refs to the NxN arrays to compare,
#       sort flag and the compare field.
# OUT - Ndx's into Right_Array of matching elements
# ---------------------------------------------------
# Notes -
# 1. Elements are assumed textual and case insensitive
# 2. Ignores in-array duplicates
# 3. Sort will be done if sort flag > 0
#
sub GetCommonElementsNxM($$$$)
{
	my ($A_Left,$A_Right,$Srtflg,$Fld)  = @_;
	$Srtflg = 0 unless defined $Srtflg;
	$Fld    = 0 unless defined $Fld;
#	my @Dup = ();
	my @Ndx = ();

	if ($Srtflg > 0) {
		@{$A_Left}  = sort {uc($a->[$Fld]) cmp uc($b->[$Fld])} @{$A_Left};
		@{$A_Right} = sort {uc($a->[$Fld]) cmp uc($b->[$Fld])} @{$A_Right};
	} else {print "==> Common Elements : Not sorting arrays\n";}

	my $rpos = 0;
	my $rend = @{$A_Right};
	my $cnt  = 0;
	my $llast = undef;
	my $rlast = undef;
	foreach my $left_element (@{$A_Left})
	{
		next if (uc($left_element->[$Fld]) eq uc($llast->[$Fld]));
		
		$rpos += $cnt;
		$cnt = 0;
		foreach my $right_element (@{$A_Right}[$rpos..($rend-1)])
		{
			last if (uc($left_element->[$Fld]) lt uc($right_element->[$Fld]));
			$cnt++;
			next if (uc($right_element->[$Fld]) eq uc($rlast->[$Fld]));
			if (uc($left_element->[$Fld]) eq uc($right_element->[$Fld]))
			{
#				push (@Dup, $right_element->[$Fld]);  # the string
				push (@Ndx, $rpos+$cnt-1);    # the index into R_Array
				last;
			}
			$rlast = $right_element;
		} 
		$llast = $left_element;
		last if ($rpos >= $rend);
	}
#	return (@Dup);
	return (@Ndx);
}


#######################################################
# Get Common Elements from single Array's
# IN  - Refs to the Nx1 arrays to compare, sort flag
# OUT - Ndx's into Right_Array of matching elements
# ---------------------------------------------------
# Notes -
# 1. Elements are assumed textual and case insensitive
# 2. Ignores in-array duplicates
# 3. Sort will be done if sort flag > 0
#######################################################
sub GetCommonElements($$$)
{
	my ($A_Left,$A_Right,$Srtflg)  = @_;
	$Srtflg = 0 unless defined $Srtflg;
#	my @Dup = ();
	my @Ndx = ();

	if ($Srtflg > 0) {
		@{$A_Left} = sort {uc($a) cmp uc($b)} @{$A_Left};
		@{$A_Right} = sort {uc($a) cmp uc($b)} @{$A_Right};
	} else {print "==> Common Elements : Not sorting arrays\n";}

	my $rpos = 0;
	my $rend = @{$A_Right};
	my $cnt  = 0;
	my $llast = '';
	my $rlast = '';
	foreach my $left_element (@{$A_Left})
	{
		next if (uc($left_element) eq uc($llast));
		
		$rpos += $cnt;
		$cnt = 0;
		foreach my $right_element (@{$A_Right}[$rpos..($rend-1)])
		{
			last if (uc($left_element) lt uc($right_element));
			$cnt++;
			next if (uc($right_element) eq uc($rlast));
			if (uc($left_element) eq uc($right_element))
			{
#				push (@Dup, $right_element);  # the string
				push (@Ndx, $rpos+$cnt-1);    # the index into R_Array
				last;
			}
			$rlast = $right_element;
		} 
		$llast = $left_element;
		last if ($rpos >= $rend);
	}
#	return (@Dup);
	return (@Ndx);
}



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

Date: Mon, 12 Jan 2009 20:35:31 GMT
From: sln@netherlands.com
Subject: Circular lists - 26 letters
Message-Id: <t5anm4d27tdcj3cdm438a1antuesh3pqvt@4ax.com>

I need to permute the 26,25,24,... letters of the alphabet.
How many words can I make with that? Will it take much memory?
How much ram do I need, how long will it take?
Do I need circular lists?

sln


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

Date: Mon, 12 Jan 2009 14:26:35 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Circular lists - 26 letters
Message-Id: <399471db-c641-4c12-be9c-b76574e0c22e@k36g2000pri.googlegroups.com>

On Jan 12, 3:35 pm, s...@netherlands.com wrote:
> I need to permute the 26,25,24,... letters of the alphabet.
> How many words can I make with that? Will it take much memory?
> How much ram do I need, how long will it take?
> Do I need circular lists?
>
> sln

See:  Math::Counting::bperm



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

Date: Mon, 12 Jan 2009 14:56:27 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Circular lists - 26 letters
Message-Id: <120120091456278835%jimsgibson@gmail.com>

In article <t5anm4d27tdcj3cdm438a1antuesh3pqvt@4ax.com>,
<sln@netherlands.com> wrote:

> I need to permute the 26,25,24,... letters of the alphabet.

Which alphabet? There are 26 letters in the English alphabet. You can
get an alphabet consisting of 25 letters by eliminating one letter from
the English alphabet. There are 26 ways to do that. You can eliminate 2
letters to get a 24-letter alphabet; there are 26*25 ways to do that.

Given N distinct letters, there are N! permutations formed by selecting
N letters from the set in order. N! = N * (N-1) * (N-2) * ... * 3 * 2 *
1 (but you knew that).

Given N distinct letters, there are N!/(N-M)! different ways to select
M letters in order from N distinct letters (M < N).

<http://en.wikipedia.org/wiki/Permutation>

> How many words can I make with that? 

Every word in the English language that does not have repeated letters,
and then some! What is your definition of a "word".

> Will it take much memory?

Not if you generate the permutations one-at-a-time. See, for example,
'perldoc -q permute'

> How much ram do I need, 

Not much (see above).

> how long will it take?

A very long time. Enough time to generate

26! + 26! + (26!/2!) + (26!/3!) + (26!/4!) + . . . + (26*25) + 26 + 1 

permutations ( or thereabouts -- my math might be off a little). Since
26! is 4.0329E26, you will need about 10**13 years assuming you can
generate and process 1,000,000 permutations per second.

> Do I need circular lists?

No.

-- 
Jim Gibson


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

Date: Mon, 12 Jan 2009 12:15:42 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Help: Cannot acquire data by split
Message-Id: <SxNal.45229$%o3.19614@newsfe02.iad>

Amy Lee wrote:

> Hello,
> 
> Here's the data I use.
> 
> ath-MIR166f Marcal1-PA 100.00 18 0 0 58 75 2226 2243 0.008 36.2
> dme-mir-278 GABA-B-R3-PA 100.00 18 0 0 64 81 282 265 0.007 36.2
> dme-mir-100 CG6630-PA 100.00 19 0 0 28 46 5108 5126 0.002 38.2
> cbr-mir-268 nop5-PA 95.65 23 1 0 57 79 1428 1406 0.001 38.2
> mmu-mir-199a-2 CG7806-PA 100.00 18 0 0 8 25 107 124 0.008 36.2
> rno-mir-320 CG15161-PA 100.00 18 0 0 2 19 265 248 0.006 36.2
> 
> And at every line the contents are separated by tab, and I used
> following syntax to get the first, second columns.
> 
> my $query_seq = (split /\t/)[0];
> my $sub_seq = (split /\t/)[1];
> 
> But the output is quite odd. The output is
> 
> Marcal1-PA Marcal1-PA
> GABA-B-R3-PA GABA-B-R3-PA
> CG6630-PA CG6630-PA
> nop5-PA nop5-PA
> CG7806-PA CG7806-PA
> CG15161-PA CG15161-PA
> 
> So could tell me how to fix that? Thanks very much.
> 
> Amy

That inconsistent output would be likely caused by some fields not being
separated by an actual tab character, but more than one white space. 
If that's a risk, it's safer to just use \s+ in place of \t+, because
it will cover both white space and tab separations of the fields.

Also, you can save some typing, and just write it as:
my ($query_seq, $sub_seq) = (split /\s+/)[0,1];

I assume you're splitting on $_ somewhere in your code.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Mon, 12 Jan 2009 20:50:09 GMT
From: sln@netherlands.com
Subject: Re: Help: Cannot acquire data by split
Message-Id: <cpanm4l3mu3ooevda1v6tih211b1kaukc2@4ax.com>

On Mon, 12 Jan 2009 08:48:48 -0600, Tad J McClellan <tadmc@seesig.invalid> wrote:

>Amy Lee <openlinuxsource@gmail.com> wrote:
>
>> Here's the data I use.
>>
>> ath-MIR166f	Marcal1-PA	100.00	18	0	0	58	75	2226	2243	0.008	36.2
>> dme-mir-278	GABA-B-R3-PA	100.00	18	0	0	64	81	282	265	0.007	36.2
>
>
>> And at every line the contents are separated by tab, and I used following
>> syntax to get the first, second columns.
>>
>> my $query_seq = (split /\t/)[0];
                   ^          ^
                       list
>> my $sub_seq = (split /\t/)[1];
                 ^          ^
                     list again
>
>
>You can do it all at once:
>
>   my($query_seq, $sub_seq) = (split /\t/)[0, 1];
>
>
>> But the output 
>
>
>The code you have shown does not make any output!
>
>I expect that you have made an error in the code that you have not shown us.
>
>Show us your output statement.
>
>
>Please post a short and complete program *that we can run* that
>demonstrates your problem.
>
>Have you seen the Posting Guidelines that are posted here frequently?

Hey Amy.
Wow, you don't want to do that. In fact split is very inefficient for
what you seem to want. To parse every single element in the record when you
only want the first two is overkill.

while (<DATA>)
{
	($element1,$element2) = /(.*?)\t(.*?)\t/;
}

sln



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

Date: Mon, 12 Jan 2009 20:57:54 GMT
From: sln@netherlands.com
Subject: Re: Help: Cannot acquire data by split
Message-Id: <ldbnm41m0ahatuc155rc0d7qsi4lusk34k@4ax.com>

On Mon, 12 Jan 2009 20:50:09 GMT, sln@netherlands.com wrote:

>On Mon, 12 Jan 2009 08:48:48 -0600, Tad J McClellan <tadmc@seesig.invalid> wrote:
>
>>Amy Lee <openlinuxsource@gmail.com> wrote:
>>
>>> Here's the data I use.
>>>
>>> ath-MIR166f	Marcal1-PA	100.00	18	0	0	58	75	2226	2243	0.008	36.2
>>> dme-mir-278	GABA-B-R3-PA	100.00	18	0	0	64	81	282	265	0.007	36.2
>>
>>
>>> And at every line the contents are separated by tab, and I used following
>>> syntax to get the first, second columns.
>>>
>>> my $query_seq = (split /\t/)[0];
>                   ^          ^
>                       list
>>> my $sub_seq = (split /\t/)[1];
>                 ^          ^
>                     list again
>>
>>
>>You can do it all at once:
>>
>>   my($query_seq, $sub_seq) = (split /\t/)[0, 1];
>>
>>
>>> But the output 
>>
>>
>>The code you have shown does not make any output!
>>
>>I expect that you have made an error in the code that you have not shown us.
>>
>>Show us your output statement.
>>
>>
>>Please post a short and complete program *that we can run* that
>>demonstrates your problem.
>>
>>Have you seen the Posting Guidelines that are posted here frequently?
>
>Hey Amy.
>Wow, you don't want to do that. In fact split is very inefficient for
>what you seem to want. To parse every single element in the record when you
>only want the first two is overkill.
>
>while (<DATA>)
>{
>	($element1,$element2) = /(.*?)\t(.*?)\t/;
>}
>
>sln

Sorry, I grabbed Tad's reply it was a mistake, thought I had Amy's original.
But, this could be even quicker:
($element1,$element2) = /\s*([^\t]+)\s+([^\t]+)\s*/;

sln



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

Date: Mon, 12 Jan 2009 14:10:02 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Help: Cannot acquire data by split
Message-Id: <_cPal.43716$1s6.30809@newsfe01.iad>

sln@netherlands.com wrote:

> On Mon, 12 Jan 2009 20:50:09 GMT, sln@netherlands.com wrote:
> 
>>On Mon, 12 Jan 2009 08:48:48 -0600, Tad J McClellan
>><tadmc@seesig.invalid> wrote:
>>
>>>Amy Lee <openlinuxsource@gmail.com> wrote:
>>>
>>>> Here's the data I use.
>>>>
>>>> ath-MIR166f        Marcal1-PA      100.00  18      0       0       58      75      2226    2243    0.008   36.2
>>>> dme-mir-278        GABA-B-R3-PA    100.00  18      0       0       64      81      282     265     0.007   36.2
>>>
>>>
>>>> And at every line the contents are separated by tab, and I used
>>>> following syntax to get the first, second columns.
>>>>
>>>> my $query_seq = (split /\t/)[0];
>>                   ^          ^
>>                       list
>>>> my $sub_seq = (split /\t/)[1];
>>                 ^          ^
>>                     list again
>>>
>>>
>>>You can do it all at once:
>>>
>>>   my($query_seq, $sub_seq) = (split /\t/)[0, 1];
>>>
>>>
>>>> But the output
>>>
>>>
>>>The code you have shown does not make any output!
>>>
>>>I expect that you have made an error in the code that you have not
>>>shown us.
>>>
>>>Show us your output statement.
>>>
>>>
>>>Please post a short and complete program *that we can run* that
>>>demonstrates your problem.
>>>
>>>Have you seen the Posting Guidelines that are posted here frequently?
>>
>>Hey Amy.
>>Wow, you don't want to do that. In fact split is very inefficient for
>>what you seem to want. To parse every single element in the record
>>when you only want the first two is overkill.
>>
>>while (<DATA>)
>>{
>>($element1,$element2) = /(.*?)\t(.*?)\t/;
>>}
>>
>>sln
> 
> Sorry, I grabbed Tad's reply it was a mistake, thought I had Amy's
> original. But, this could be even quicker:
> ($element1,$element2) = /\s*([^\t]+)\s+([^\t]+)\s*/;
> 
> sln

I'd imagine that the split example will actually be about the same in
efficiency as the regex, since it's splitting at [0,1] and, in fact,
I'd wager that the split method in the examples would probably be
faster.  Feel free to benchmark.  I'm betting that be it iterations of
a million times (or even 10 million), that split would probably be
slightly faster than the regex.  Also, you probably want to use /^\s*
to start your regex (not that it'll matter for speed as much as the
obvious reason), and use \s in place of \t, since the inconsistent
results will be due to non tabs in the original example.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Mon, 12 Jan 2009 22:33:13 GMT
From: sln@netherlands.com
Subject: Re: Help: Cannot acquire data by split
Message-Id: <b6hnm417fbf79giir8pkb4ejtcc7oefnii@4ax.com>

On Mon, 12 Jan 2009 14:10:02 -0800, Tim Greer <tim@burlyhost.com> wrote:

>sln@netherlands.com wrote:
>
>> On Mon, 12 Jan 2009 20:50:09 GMT, sln@netherlands.com wrote:
>> 
>>>On Mon, 12 Jan 2009 08:48:48 -0600, Tad J McClellan
>>><tadmc@seesig.invalid> wrote:
>>>
>>>>Amy Lee <openlinuxsource@gmail.com> wrote:
>>>>
>>>>> Here's the data I use.
>>>>>
>>>>> ath-MIR166f        Marcal1-PA      100.00  18      0       0       58      75      2226    2243    0.008   36.2
>>>>> dme-mir-278        GABA-B-R3-PA    100.00  18      0       0       64      81      282     265     0.007   36.2
>>>>
>>>>
>>>>> And at every line the contents are separated by tab, and I used
>>>>> following syntax to get the first, second columns.
>>>>>
>>>>> my $query_seq = (split /\t/)[0];
>>>                   ^          ^
>>>                       list
>>>>> my $sub_seq = (split /\t/)[1];
>>>                 ^          ^
>>>                     list again
>>>>
>>>>
>>>>You can do it all at once:
>>>>
>>>>   my($query_seq, $sub_seq) = (split /\t/)[0, 1];
>>>>
>>>>
>>>>> But the output
>>>>
>>>>
>>>>The code you have shown does not make any output!
>>>>
>>>>I expect that you have made an error in the code that you have not
>>>>shown us.
>>>>
>>>>Show us your output statement.
>>>>
>>>>
>>>>Please post a short and complete program *that we can run* that
>>>>demonstrates your problem.
>>>>
>>>>Have you seen the Posting Guidelines that are posted here frequently?
>>>
>>>Hey Amy.
>>>Wow, you don't want to do that. In fact split is very inefficient for
>>>what you seem to want. To parse every single element in the record
>>>when you only want the first two is overkill.
>>>
>>>while (<DATA>)
>>>{
>>>($element1,$element2) = /(.*?)\t(.*?)\t/;
>>>}
>>>
>>>sln
>> 
>> Sorry, I grabbed Tad's reply it was a mistake, thought I had Amy's
>> original. But, this could be even quicker:
>> ($element1,$element2) = /\s*([^\t]+)\s+([^\t]+)\s*/;
>> 
>> sln
>
>I'd imagine that the split example will actually be about the same in
>efficiency as the regex, since it's splitting at [0,1] and, in fact,
>I'd wager that the split method in the examples would probably be
>faster.  Feel free to benchmark.  I'm betting that be it iterations of
>a million times (or even 10 million), that split would probably be
>slightly faster than the regex.  Also, you probably want to use /^\s*
>to start your regex (not that it'll matter for speed as much as the
>obvious reason), and use \s in place of \t, since the inconsistent
>results will be due to non tabs in the original example.

Interresting, I was just thinking if split() is deep C<> you may be
right. Then I started thinking it uses the regex engine. Nope, not faster then!

sln



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

Date: Mon, 12 Jan 2009 22:38:51 GMT
From: sln@netherlands.com
Subject: Re: Help: Cannot acquire data by split
Message-Id: <bhhnm4h84o7abd45ur1c97t31fnahckigd@4ax.com>

On Mon, 12 Jan 2009 14:10:02 -0800, Tim Greer <tim@burlyhost.com> wrote:

>sln@netherlands.com wrote:
>
>> On Mon, 12 Jan 2009 20:50:09 GMT, sln@netherlands.com wrote:
>> 
>>>On Mon, 12 Jan 2009 08:48:48 -0600, Tad J McClellan
>>><tadmc@seesig.invalid> wrote:
>>>
>>>>Amy Lee <openlinuxsource@gmail.com> wrote:
>>>>
>>>>> Here's the data I use.
>>>>>
>>>>> ath-MIR166f        Marcal1-PA      100.00  18      0       0       58      75      2226    2243    0.008   36.2
>>>>> dme-mir-278        GABA-B-R3-PA    100.00  18      0       0       64      81      282     265     0.007   36.2
>>>>
>>>>
>>>>> And at every line the contents are separated by tab, and I used
>>>>> following syntax to get the first, second columns.
>>>>>
>>>>> my $query_seq = (split /\t/)[0];
>>>                   ^          ^
>>>                       list
>>>>> my $sub_seq = (split /\t/)[1];
>>>                 ^          ^
>>>                     list again
>>>>
>>>>
>>>>You can do it all at once:
>>>>
>>>>   my($query_seq, $sub_seq) = (split /\t/)[0, 1];
>>>>
>>>>
>>>>> But the output
>>>>
>>>>
>>>>The code you have shown does not make any output!
>>>>
>>>>I expect that you have made an error in the code that you have not
>>>>shown us.
>>>>
>>>>Show us your output statement.
>>>>
>>>>
>>>>Please post a short and complete program *that we can run* that
>>>>demonstrates your problem.
>>>>
>>>>Have you seen the Posting Guidelines that are posted here frequently?
>>>
>>>Hey Amy.
>>>Wow, you don't want to do that. In fact split is very inefficient for
>>>what you seem to want. To parse every single element in the record
>>>when you only want the first two is overkill.
>>>
>>>while (<DATA>)
>>>{
>>>($element1,$element2) = /(.*?)\t(.*?)\t/;
>>>}
>>>
>>>sln
>> 
>> Sorry, I grabbed Tad's reply it was a mistake, thought I had Amy's
>> original. But, this could be even quicker:
>> ($element1,$element2) = /\s*([^\t]+)\s+([^\t]+)\s*/;
>> 
>> sln
>
>I'd imagine that the split example will actually be about the same in
>efficiency as the regex, since it's splitting at [0,1] and, in fact,
>I'd wager that the split method in the examples would probably be
>faster.  Feel free to benchmark.  I'm betting that be it iterations of
>a million times (or even 10 million), that split would probably be
>slightly faster than the regex.  Also, you probably want to use /^\s*
>to start your regex (not that it'll matter for speed as much as the
>obvious reason), and use \s in place of \t,
Can't, Amy has spaces in her elements, the delimeter is \t. \s is a slight
safety factor IMO.
> since the inconsistent
>results will be due to non tabs in the original example.

sln



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

Date: Mon, 12 Jan 2009 14:50:49 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Help: Cannot acquire data by split
Message-Id: <dPPal.7854$Ew6.2236@newsfe22.iad>

sln@netherlands.com wrote:

> On Mon, 12 Jan 2009 14:10:02 -0800, Tim Greer <tim@burlyhost.com>
> wrote:
> 
>>sln@netherlands.com wrote:
>>
>>> On Mon, 12 Jan 2009 20:50:09 GMT, sln@netherlands.com wrote:
>>> 
>>>>On Mon, 12 Jan 2009 08:48:48 -0600, Tad J McClellan
>>>><tadmc@seesig.invalid> wrote:
>>>>
>>>>>Amy Lee <openlinuxsource@gmail.com> wrote:
>>>>>
>>>>>> Here's the data I use.
>>>>>>
>>>>>> ath-MIR166f        Marcal1-PA      100.00  18      0       0     
>>>>>>  58      75      2226    2243    0.008   36.2
>>>>>> dme-mir-278        GABA-B-R3-PA    100.00  18      0       0     
>>>>>>  64      81      282     265     0.007   36.2
>>>>>
>>>>>
>>>>>> And at every line the contents are separated by tab, and I used
>>>>>> following syntax to get the first, second columns.
>>>>>>
>>>>>> my $query_seq = (split /\t/)[0];
>>>>                   ^          ^
>>>>                       list
>>>>>> my $sub_seq = (split /\t/)[1];
>>>>                 ^          ^
>>>>                     list again
>>>>>
>>>>>
>>>>>You can do it all at once:
>>>>>
>>>>>   my($query_seq, $sub_seq) = (split /\t/)[0, 1];
>>>>>
>>>>>
>>>>>> But the output
>>>>>
>>>>>
>>>>>The code you have shown does not make any output!
>>>>>
>>>>>I expect that you have made an error in the code that you have not
>>>>>shown us.
>>>>>
>>>>>Show us your output statement.
>>>>>
>>>>>
>>>>>Please post a short and complete program *that we can run* that
>>>>>demonstrates your problem.
>>>>>
>>>>>Have you seen the Posting Guidelines that are posted here
>>>>>frequently?
>>>>
>>>>Hey Amy.
>>>>Wow, you don't want to do that. In fact split is very inefficient
>>>>for what you seem to want. To parse every single element in the
>>>>record when you only want the first two is overkill.
>>>>
>>>>while (<DATA>)
>>>>{
>>>>($element1,$element2) = /(.*?)\t(.*?)\t/;
>>>>}
>>>>
>>>>sln
>>> 
>>> Sorry, I grabbed Tad's reply it was a mistake, thought I had Amy's
>>> original. But, this could be even quicker:
>>> ($element1,$element2) = /\s*([^\t]+)\s+([^\t]+)\s*/;
>>> 
>>> sln
>>
>>I'd imagine that the split example will actually be about the same in
>>efficiency as the regex, since it's splitting at [0,1] and, in fact,
>>I'd wager that the split method in the examples would probably be
>>faster.  Feel free to benchmark.  I'm betting that be it iterations of
>>a million times (or even 10 million), that split would probably be
>>slightly faster than the regex.  Also, you probably want to use /^\s*
>>to start your regex (not that it'll matter for speed as much as the
>>obvious reason), and use \s in place of \t,
> Can't, Amy has spaces in her elements, the delimeter is \t. \s is a
> slight safety factor IMO.
>> since the inconsistent
>>results will be due to non tabs in the original example.
> 
> sln

Sorry, I can't make out where you replied to me above?  Were you saying
the OP had spaces in one or more of their fields?  If so, then yea, tab
delimited files would need to use \t, but her inconsistent results
reported would indicate that they weren't actual tabs.  If it's a
matter of fields with a white space, perhaps try using (\t|\s{2,}) so
you can split on either, but not on fields with a single white space? 
Or, for that matter, \s{4,} so it'll only split on tabs or white space
with 4 or more (seen as tabs to some editors) and not risk splitting on
a field's white space?  Of course, I'm only guessing at their problem.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Mon, 12 Jan 2009 12:07:28 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: how to encrypt password stored in ftp script
Message-Id: <5qNal.15531$2w3.10129@newsfe19.iad>

Woland99 wrote:

> Howdy - I want my script to make connection to FTP server and get some
> files. I need that script to run everyday automatically on machine
> that many people
> have access to - but I do not want them to know the username or
> password for that
> FTP server. Is there a way to save encrypted password with the script
> but prevent
> people form modifying script to access the FTP server for different
> purposes?
> 
> JT

FTP is clear text, you can't encrypt it, unless you decrypt somewhere in
the process (or on the other end), which probably defeats the purpose,
since that's the method someone else would just be able to use anyway. 
I could only suggest using sftp, scp or rsync over SSH with a trusted
key.  Of course, the problem is, if people have access to the system,
it doesn't matter a whole lot, since the trusted key allows them access
without a password.  Otherwise, they can see the password in plain
text, which means they have the same trusted access once authenticated
-- and besides having that access, they have the password as well.

You can also time it with firewalls to only allow connections from the
system to the server at certain times.  The best solution, is if you're
uploading from the system, is to find the most secure way of doing it,
but make it so that the FTP account it uploads to, is separate from
anything else (not full or other access to the remote account you
upload to).  Make it so you can only upload (the files can be hidden
from view on the client end once they are uploaded).  For the script
initiating this, you can try and hide the file name, the job, and also
make it so only your user has read permissions on the script used (the
last part is the most important -- how are you at risk of others
reading the script or being able to log into your account that runs
this process?  That's the biggest problem you should find a resolution
for).  You make it sound like this is a system that anyone can access,
is that the case?  If so, what's stopping people from reading any of
your data or modifying that data?

Ultimately, if this is a system where anyone can access and somehow view
or gain access to the script or password, you should initiate the FTP
session (or better yet, a more secure method) from the _server_ side
(where you want the files stored) and have it connect to the system and
transfer the files _from_ it, which is the best scenario in this case
regardless of how people can access it (assuming the other end is more
secure).  That way, none of the other users on the system you're
wanting to transfer files from, will have a way to access the server
end.  You can do that with trusted keys or some more secure transfer
method, but FTP will work fine as well, assuming the server end can be
trusted with the same dilemma you have on the system in question.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Mon, 12 Jan 2009 14:12:06 -0700
From: George <george@example.invalid>
Subject: Re: opening a file
Message-Id: <yxs69cha40il.pf3fh2zetgv9.dlg@40tude.net>

On Sun, 11 Jan 2009 22:38:58 -0600, Tad J McClellan wrote:

> George <george@example.invalid> wrote:

> All of Perl's variables are documented in:
> 
>    perldoc perlvar
> 
> I don't remember what fortran called it, but Perl's $! is errno in C.
> 
> If used as a string rather than a number, then perl will look up
> that error number for you, and its value will be "permission denied"
> or "file not found" or some such.

There's a lot to learn there.  What a motley crüe of variables comes with
the porridge in perl!

This is pretty straightforward:


    $!      If used numerically, yields the current value of the C "errno"
            variable, or in other words, if a system or library call fails,
            it sets this variable. This means that the value of $! is
            meaningful only *immediately* after a failure:

                if (open(FH, $filename)) {
                    # Here $! is meaningless.
                    ...
                } else {
                    # ONLY here is $! meaningful.
                    ...
                    # Already here $! might be meaningless.
                }
                # Since here we might have either success or failure,
                # here $! is meaningless.

            In the above *meaningless* stands for anything: zero, non-zero,
            "undef". A successful system or library call does not set the
            variable to zero.

            If used as a string, yields the corresponding system error
            string. You can assign a number to $! to set *errno* if, for
            instance, you want "$!" to return the string for error *n*, or
            you want to set the exit value for the die() operator.
            (Mnemonic: What just went bang?)

I don't get the mnemonic.

>       
> 
>> How does perl.exe know whether the third argument is an expression or a
>> reference?
> 
> 
>     perldoc -f ref

    ref EXPR
    ref     Returns a non-empty string if EXPR is a reference, the empty
            string otherwise. If EXPR is not specified, $_ will be used.
The value returned depends on the type of thing the reference is a
reference to. Builtin types include:
# end excerpt

I don't see this at all.

    open FILEHANDLE,MODE,EXPR
    open FILEHANDLE,MODE,REFERENCE

Is this the difference between:

   open(my $fh, '<', 'eph3.txt');
   open(my $fh, '<', $filename);
?


-- 
George

I sent American troops to Iraq to make its people free, not to make them
American. Iraqis will write their own history and find their own way.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/


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

Date: Mon, 12 Jan 2009 15:01:03 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: opening a file
Message-Id: <120120091501035336%jimsgibson@gmail.com>

In article <yxs69cha40il.pf3fh2zetgv9.dlg@40tude.net>, George
<george@example.invalid> wrote:

> On Sun, 11 Jan 2009 22:38:58 -0600, Tad J McClellan wrote:
> 

>     $!      If used numerically, yields the current value of the C "errno"

 ...

>             (Mnemonic: What just went bang?)
> 
> I don't get the mnemonic.

"bang" is the common, short-form name of the "exclamation-point"
character '!'. Thus, the string '#!' is read as "pound bang", "hash
bang", or colloquially as "she-bang" (not sure about the derivation of
the last).

-- 
Jim Gibson


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

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 V11 Issue 2118
***************************************


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