[21711] in Perl-Users-Digest
Perl-Users Digest, Issue: 3915 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 4 14:13:20 2002
Date: Fri, 4 Oct 2002 11:10:16 -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 Fri, 4 Oct 2002 Volume: 10 Number: 3915
Today's topics:
Re: Script to Change Filename (Helgi Briem)
Re: Script to Change Filename (Tad McClellan)
Re: Script to Change Filename <wsegrave@mindspring.com>
Re: Script to Change Filename <wsegrave@mindspring.com>
Re: Script to Change Filename <wsegrave@mindspring.com>
Re: Script to Change Filename <jurgenex@hotmail.com>
Setting your dos window size, title and colour! <spikey-wan@bigfoot.com>
Splitting Up A String (Vivek)
Re: Splitting Up A String <daniel.heiserer@bmw.de>
Re: Splitting Up A String <krahnj@acm.org>
Re: Splitting Up A String (Helgi Briem)
Re: Splitting Up A String (Tad McClellan)
Re: Splitting Up A String (Helgi Briem)
unzip/zip an array <daniel.heiserer@bmw.de>
Re: unzip/zip an array <krahnj@acm.org>
Re: unzip/zip an array <daniel.heiserer@bmw.de>
Re: unzip/zip an array (Helgi Briem)
Re: unzip/zip an array <krahnj@acm.org>
Re: unzip/zip an array <daniel.heiserer@bmw.de>
Re: unzip/zip an array <krahnj@acm.org>
Re: unzip/zip an array <Graham.T.Wood@oracle.com>
Re: unzip/zip an array <jhalpin@nortelnetworks.com_.nospam>
Re: unzip/zip an array <Tassilo.Parseval@post.rwth-aachen.de>
Re: unzip/zip an array <goldbb2@earthlink.net>
webmail & strange characters <defalco@hotmail.com>
Re: Win32::Console <spikey-wan@bigfoot.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 04 Oct 2002 13:23:56 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Script to Change Filename
Message-Id: <3d9d922c.2176848122@news.cis.dfn.de>
On Fri, 04 Oct 2002 12:07:48 GMT, "JP"
<NO_SPAM_pangjoe@rogers.com> wrote:
Don't top-post. It annoys the regulars and severely
reduces your chances of getting useful answers to
your questions.
For further information on posting to clp.misc, see
the Posting Guidelines at:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
For more information about netiquette in general, see
the "Netiquette Guidelines" at:
http://andrew2.andrew.cmu.edu/rfc/rfc1855.html
>Sorry for being unclear. Let me rephrase my question:
>
>In a directory with thousands of different files, I have to choose those
>with names in the format "nnnnnx.dat", where
> nnnnn is numeric (0-9) and can 3 to 8 digits
> x is an alphabet (A-Z, a-z)
> .dat is the file extension (to be used with DOS/Windows
> applications)
>
>Once a file meets the criteria, it should be renamed by inserting a "-"
>between the numeric part and the alphabet, i.e. nnnnnx.dat will become
>nnnnn-x.dat.
Here is one way:
#!perl
use warnings;
use strict;
my $dir = '/what/ever';
opendir DIR, $dir or die "Cannot opendir $dir:$!\n";
for (readdir DIR)
{
if (/^(\d{3,8})([a-zA-Z]\.dat)$/i)
{
my $old = "$dir/$_";
my $new = "$dir/${1}-${2}";
print "Renaming $old, $new\n";
rename $old, $new or warn "Cannot rename $old to
$new:$!\n";
}
}
closedir DIR;
__END__
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Fri, 4 Oct 2002 08:59:55 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Script to Change Filename
Message-Id: <slrnapr7mr.31t.tadmc@magna.augustmail.com>
[ Please learn to quote properly. That is don't top-post/full-quote.
Do provide an attribution when you quote someone.
Text rearranged into actual chronology.
]
JP <NO_SPAM_pangjoe@rogers.com> wrote:
[ It looks like Bill Segraves wrote: ]
>> my @filenames = ("12345a.dat", "12345b.dat", "0123456789c.dat",
You (Bill) missed an important test case. Try "123a.datum" :-)
>> foreach (@filenames){
>> s/((?:\d)+)([a-zA-Z]\.dat)/${1}-${2}/; #regex from David Britten
^^
^^ need an anchor here
> Unfortunately, I have over 1,000 files which make
> it impossible to be defined in an array.
You gave 3 points in your original post, and said you were having
trouble with #2, so it is assumed that you can get the filenames
(#1) into an array somehow.
> I have to pick from a directory
> which has other files not to be renamed as well.
If you need help with #1 also, then you should say that.
Your OP implies that that part is not a problem for you.
> But I have to choose those
> with names in the format "nnnnnx.dat", where
> nnnnn is numeric but can 3 to 8 digits
> x is an alphabet
> .dat is the file extension
Bill's code already does all of that except the "3 to 8 digits" part.
You can fix it to account for this late-breaking addition to
the specification easily, you need 2 changes.
Anchor the beginning (and end) of the pattern
Change the + to {3,8}
> Once a file meets the criteria, it should be renamed by inserting a "-"
> between the numeric part and the alphabet, i.e. nnnnnx.dat will become
> nnnnn-x.dat.
Make the changes, and Bill's code does that.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 4 Oct 2002 10:24:48 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Script to Change Filename
Message-Id: <ankc67$3m2$1@slb3.atl.mindspring.net>
"JP" <NO_SPAM_pangjoe@rogers.com> wrote in message
news:7tfn9.177797$8b1.144811@news01.bloor.is.net.cable.rogers.com...
> Bill,
>
> Thanks for your efforts. Unfortunately, I have over 1,000 files which
make
> it impossible to be defined in an array. I have to pick from a directory
> which has other files not to be renamed as well. But I have to choose
those
> with names in the format "nnnnnx.dat", where
> nnnnn is numeric but can 3 to 8 digits
> x is an alphabet
> .dat is the file extension
>
> Once a file meets the criteria, it should be renamed by inserting a "-"
> between the numeric part and the alphabet, i.e. nnnnnx.dat will become
> nnnnn-x.dat.
>
Joe,
1. Please don't top post.
2. My little script was intended only to show that the regex provided by
late-night respondent David Britten met your original spec. It was _really_
late for me, so I (implicitly) left the task of how to use it to you. See
Chapter 13 of _Learning Perl_, 2nd. ed, "File and Directory Manipulation"
(or the equiv. section of a later edition), for ideas on how to proceed,
e.g.,
my $old = $_;
s/((?:\d)+)([a-zA-Z]\.dat)/${1}-${2}/; #regex from David Britten (orig spec)
my $new = $_;
rename ($old, $new) || warn "Can't rename $old to $new: $!";
[Partially tested in modification of my previous script. Works fine here.
YMMV.]
I'll leave it to you to figure out how to get filenames, one at a time, into
$_. See Tina Mueller's and Helgi Briem's posts for what are likely to be
complete solutions for your old and new specs, respectively.
Cheers,
Bill Segraves
------------------------------
Date: Fri, 4 Oct 2002 11:21:40 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Script to Change Filename
Message-Id: <ankfj3$qs1$1@slb3.atl.mindspring.net>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnapr7mr.31t.tadmc@magna.augustmail.com...
>
> [ Please learn to quote properly. That is don't top-post/full-quote.
> Do provide an attribution when you quote someone.
>
I think the top posters can see how much waste of valuable time, this time
Tad's, that top posting creates. Correct me if I'm wrong, Tad; but I believe
all of my post was in chronalogical order. Perhaps I should have snipped a
bit of the text; but, in review, I see I'd have to have all/most of what I
quoted to understand the context.
<snip>
> [ It looks like Bill Segraves wrote: ]
>
>
> >> my @filenames = ("12345a.dat", "12345b.dat", "0123456789c.dat",
>
>
> You (Bill) missed an important test case. Try "123a.datum" :-)
I did, indeed. OTOH, the case "0123d.dat.html" that I _did_ include shows
the same behaviour, i.e., dash is inserted.
Now you've given me a reason to use a "belt and suspenders" approach, i.e.,
dir *.bat > filenames.txt
to get the list of files to process.
> >> foreach (@filenames){
> >> s/((?:\d)+)([a-zA-Z]\.dat)/${1}-${2}/; #regex from David Britten
> ^^
> ^^ need an anchor here
>
OP and David Britten. Please take note of Tad's suggestions. They're good
ones.
<snip>
> > I have to pick from a directory
> > which has other files not to be renamed as well.
OP might wish to shorten the list to be processed by processing only *.dat
files.
<snip>
> Bill's code already does all of that except the "3 to 8 digits" part.
>
> You can fix it to account for this late-breaking addition to
> the specification easily, you need 2 changes.
>
> Anchor the beginning (and end) of the pattern
>
> Change the + to {3,8}
>
>
> > Once a file meets the criteria, it should be renamed by inserting a "-"
> > between the numeric part and the alphabet, i.e. nnnnnx.dat will become
> > nnnnn-x.dat.
>
>
> Make the changes, and Bill's code does that.
OP, please make these changes to David Britten's regex and see if they fix
your problems and meet your revised spec. Works fine here. YMMV. Revised
_test_ script follows:
#!perl -w
# filedasher_v2a.pl- adds dashes into filenames, e.g., 12345a.dat becomes
12345-a.dat
use strict;
my @filenames = ("12345a.dat", "12345b.dat", "0123456789c.dat", "a123b.bat",
"index1.html", "0123d.dat.html", "123a.datum");
foreach (@filenames){
s/^((?:\d){3,8})([a-zA-Z]\.dat)$/${1}-${2}/; #regex from David Britten, with
mods from Tad McClellan
print $_, "\n";
}
Thanks to David Britten and Tad McClellan for valuable contributions.
Cheers,
Bill Segraves
------------------------------
Date: Fri, 4 Oct 2002 11:26:03 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Script to Change Filename
Message-Id: <ankfj4$qs1$2@slb3.atl.mindspring.net>
"William Alexander Segraves" <wsegrave@mindspring.com> wrote in message
news:ankc67$3m2$1@slb3.atl.mindspring.net...
<snip>
> my $old = $_;
> s/((?:\d)+)([a-zA-Z]\.dat)/${1}-${2}/; #regex from David Britten (orig
spec)
> my $new = $_;
> rename ($old, $new) || warn "Can't rename $old to $new: $!";
>
> [Partially tested in modification of my previous script. Works fine here.
> YMMV.]
Substitute
s/^((?:\d){3,8})([a-zA-Z]\.dat)$/${1}-${2}/; #regex from David Britten, with
mods from Tad McClellan
in place of David's regex to meet revised spec.
Cheer,
Bill Segraves
------------------------------
Date: Fri, 4 Oct 2002 10:23:22 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Script to Change Filename
Message-Id: <3d9dce8a$1@news.microsoft.com>
William Alexander Segraves wrote:
> "JP" <NO_SPAM_pangjoe@rogers.com> wrote in message
> news:7tfn9.177797$8b1.144811@news01.bloor.is.net.cable.rogers.com...
>> Bill,
>>
>> Thanks for your efforts. Unfortunately, I have over 1,000 files
>> which
> make
>> it impossible to be defined in an array.
Why? Perl can handle arrays with thousands of elements without any problems.
>> I have to pick from a
>> directory which has other files not to be renamed as well. But I
Either read the directory content (hint: perldoc -f readdir) and filter for
the wanted files (hint: perldoc -f grep) or use File::Find with a proper
wanted() function.
>> have to choose those with names in the format "nnnnnx.dat", where
>> nnnnn is numeric but can 3 to 8 digits
\d{3,8}
>> x is an alphabet
What do you mean by alphabet? An English letter?
[a-zA-Z]
>> .dat is the file extension
The dot needs to be escaped, otherwise it will be interpreted as a wildcard.
>>
>> Once a file meets the criteria, it should be renamed by inserting a
perldoc -f rename
>> "-" between the numeric part and the alphabet, i.e. nnnnnx.dat will
>> become nnnnn-x.dat.
s/(\d{3,8})([a-zA-Z])\.dat/$1-$2.dat/
to get the new filename
jue
------------------------------
Date: Fri, 4 Oct 2002 16:42:45 +0100
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Setting your dos window size, title and colour!
Message-Id: <ankcut$lek$1@newshost.mot.com>
Guys,
After much trawling google.com, I have found out how to resize and set the
colours for the dos window that your perl script runs in.
Try this:
system ("color 17"); # Type help color at the dos prompt to see what the
colours are
# the 1 is the foreground colour (white) and 7 is the background colour
(blue)
system ("title My Title"); # This titles the window
system ("mode con: cols=80 lines=50"); # this sets the size of the window.
Share and Enjoy! :-)
Now, does anyone know what else you can do with:
system ("mode con:...
I'd like to be able to set the buffer size, too.
Thanks.
R.
------------------------------
Date: 4 Oct 2002 08:13:36 -0700
From: vgtek@yahoo.com (Vivek)
Subject: Splitting Up A String
Message-Id: <67965b1c.0210040713.6f70b952@posting.google.com>
I've just started learning perl, and i was working on a problem which
deals with cutting up a protein sequence. I'm supposed to create a
'cut' subroutine which cuts up a protein sequence according to a
specified regular expression and location.
For example if my protein sequence was:
'QWGCSDLPFGERTYWGGP'
And the regular expression I gave was FGER and position was 1
I should get the two subsequences:
'QWGCSDLPF' and 'GERTYWGGP'
I guess I would have to match, but then I don't know how to split it.
My Question is, how would I use split to split up the string, into the
smaller strings?
Thanks --Vivek
------------------------------
Date: Fri, 04 Oct 2002 17:28:55 +0200
From: HEISERER DANIEL <daniel.heiserer@bmw.de>
Subject: Re: Splitting Up A String
Message-Id: <3D9DB3B7.D6EAC9A2@bmw.de>
This is a multi-part message in MIME format.
--------------5B0C8CE62929AAAD6006C292
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
> I've just started learning perl, and i was working on a problem which
> deals with cutting up a protein sequence. I'm supposed to create a
> 'cut' subroutine which cuts up a protein sequence according to a
> specified regular expression and location.
> For example if my protein sequence was:
> 'QWGCSDLPFGERTYWGGP'
> And the regular expression I gave was FGER and position was 1
> I should get the two subsequences:
> 'QWGCSDLPF' and 'GERTYWGGP'
you "should get" or "you want to get"?
>
> I guess I would have to match, but then I don't know how to split it.
> My Question is, how would I use split to split up the string, into the
> smaller strings?
what do you want??
@T=split('FGER','QWGCSDLPFGERTYWGGP');
#results in
@T=('QWGCSDLPF','GERTYWGGP');
--dh
--------------5B0C8CE62929AAAD6006C292
Content-Type: text/x-vcard; charset=us-ascii;
name="daniel.heiserer.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for HEISERER DANIEL
Content-Disposition: attachment;
filename="daniel.heiserer.vcf"
begin:vcard
n:Daniel;Heiserer,
tel;fax:41696
tel;home:1409782
tel;work:21187
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:daniel.heiserer@bmw.de
x-mozilla-cpt:;-3136
fn:Heiserer, Daniel
end:vcard
--------------5B0C8CE62929AAAD6006C292--
------------------------------
Date: Fri, 04 Oct 2002 15:39:42 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Splitting Up A String
Message-Id: <3D9DB63A.A4D5DB94@acm.org>
Vivek wrote:
>
> I've just started learning perl, and i was working on a problem which
> deals with cutting up a protein sequence. I'm supposed to create a
> 'cut' subroutine which cuts up a protein sequence according to a
> specified regular expression and location.
> For example if my protein sequence was:
> 'QWGCSDLPFGERTYWGGP'
> And the regular expression I gave was FGER and position was 1
> I should get the two subsequences:
> 'QWGCSDLPF' and 'GERTYWGGP'
>
> I guess I would have to match, but then I don't know how to split it.
> My Question is, how would I use split to split up the string, into the
> smaller strings?
$ perl -e'
$seq = "QWGCSDLPFGERTYWGGP";
$cut = "FGER";
$pos = 1;
$found = index $seq, $cut;
$subseq1 = substr $seq, 0, $found + $pos;
$subseq2 = substr $seq, $found + $pos;
print "$subseq1\n$subseq2\n";
'
QWGCSDLPF
GERTYWGGP
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 04 Oct 2002 15:52:38 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Splitting Up A String
Message-Id: <3d9db87e.2186659600@news.cis.dfn.de>
On 4 Oct 2002 08:13:36 -0700, vgtek@yahoo.com (Vivek) wrote:
>I've just started learning perl, and i was working on a problem which
>deals with cutting up a protein sequence. I'm supposed to create a
>'cut' subroutine which cuts up a protein sequence according to a
>specified regular expression and location.
>For example if my protein sequence was:
>'QWGCSDLPFGERTYWGGP'
>And the regular expression I gave was FGER and position was 1
>I should get the two subsequences:
>'QWGCSDLPF' and 'GERTYWGGP'
Others can probably come up with more elegant ways,
but this one at least works. It becomes slightly more
complex if the site can mach in multiple locations.
For $stern and $bow you could substitute $N_terminus
and $C_terminus if you feel so inclined.
#!perl
use warnings;
use strict;
my $protein = 'QWGCSDLPFGERTYWGGP';
my $site = 'FGER';
my $pos = 1;
my ($stern,$bow) = split /$site/,$protein;
my $stern_extension = substr $site,0,$pos;
(my $bow_extension = $site) =~ s/^$stern_extension//;
$stern = $stern . $stern_extension;
$bow = $bow_extension . $bow;
print "$stern\n$bow\n";
__END__
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Fri, 4 Oct 2002 11:15:55 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Splitting Up A String
Message-Id: <slrnaprflr.1sp.tadmc@magna.augustmail.com>
Vivek <vgtek@yahoo.com> wrote:
> I've just started learning perl, and i was working on a problem which
> deals with cutting up a protein sequence. I'm supposed to create a
> 'cut' subroutine which cuts up a protein sequence according to a
> specified regular expression and location.
> For example if my protein sequence was:
> 'QWGCSDLPFGERTYWGGP'
> And the regular expression I gave was FGER and position was 1
^^^^^^^^^^^^^^^^^^ ^^^^
That doesn't look like it _has_ to be a regular expression.
Can you use regex metachars in it (eg: F..R or F[GE][GE]R), or is
it really going to be only a (sub)string?
> I should get the two subsequences:
> 'QWGCSDLPF' and 'GERTYWGGP'
>
> I guess I would have to match, but then I don't know how to split it.
> My Question is, how would I use split
You shouldn't really restrict the form of the solution like that.
It leaves out other (potentially better) solutions that do
not use split(), like mine below. :-)
> to split up the string, into the
> smaller strings?
--------------------------------------------
sub slice_protein {
my($seq, $substr, $pos) = @_;
my $index = index $seq, $substr;
return () unless $index >= 0; # not found
return substr($seq, 0, $index+$pos), substr($seq, $index+$pos);
}
--------------------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 04 Oct 2002 16:25:11 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Splitting Up A String
Message-Id: <3d9dc010.2188597817@news.cis.dfn.de>
On Fri, 4 Oct 2002 11:15:55 -0500, tadmc@augustmail.com (Tad
McClellan) wrote:
>That doesn't look like it _has_ to be a regular expression.
>
>Can you use regex metachars in it (eg: F..R or F[GE][GE]R), or is
>it really going to be only a (sub)string?
The OP doesn't say, but I suspect that to be any use
for real-life applications in protein analysis, it would
have to be a regular expression rather than a substring.
The amino acids in proteins (the letters) can be
grouped into different categories with similar
properties within each category. Frequently, a
particular amino acid could be substituted by
any other in that category without any change
in biological function.
On the other hand, for applications other than
what I have in mind, the OP might want a fixed string.
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Fri, 04 Oct 2002 16:58:19 +0200
From: HEISERER DANIEL <daniel.heiserer@bmw.de>
Subject: unzip/zip an array
Message-Id: <3D9DAC8B.2628A118@bmw.de>
This is a multi-part message in MIME format.
--------------81BE9509A3F1710B5B290918
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
Assume I have an array:
@T=("a","b","c","d",......);
I want to split (unzip) this array into two arrays:
@T1=("a","c",......);
@T2=("b","d",.....);
How is it done (I mean the cool way ;-), not some loops)?
Once I have @T1 and @T2 how can I form (zip) them togehter
into @T again?
thanks, daniel
--------------81BE9509A3F1710B5B290918
Content-Type: text/x-vcard; charset=us-ascii;
name="daniel.heiserer.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for HEISERER DANIEL
Content-Disposition: attachment;
filename="daniel.heiserer.vcf"
begin:vcard
n:Daniel;Heiserer,
tel;fax:41696
tel;home:1409782
tel;work:21187
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:daniel.heiserer@bmw.de
x-mozilla-cpt:;-3136
fn:Heiserer, Daniel
end:vcard
--------------81BE9509A3F1710B5B290918--
------------------------------
Date: Fri, 04 Oct 2002 15:27:25 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: unzip/zip an array
Message-Id: <3D9DB354.C06B91E5@acm.org>
HEISERER DANIEL wrote:
>
> Assume I have an array:
>
> @T=("a","b","c","d",......);
>
> I want to split (unzip) this array into two arrays:
>
> @T1=("a","c",......);
> @T2=("b","d",.....);
>
> How is it done (I mean the cool way ;-), not some loops)?
$ perl -e'
@T = qw/a b c d e f g h/;
print "@T\n";
push @{ --$| ? \@T1 : \@T2 }, $_ for @T;
print "@T1\n@T2\n";
'
a b c d e f g h
a c e g
b d f h
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 04 Oct 2002 17:35:29 +0200
From: HEISERER DANIEL <daniel.heiserer@bmw.de>
To: "John W. Krahn" <krahnj@acm.org>
Subject: Re: unzip/zip an array
Message-Id: <3D9DB541.99ED9842@bmw.de>
This is a multi-part message in MIME format.
--------------9377734B5A378DEA475EB428
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
"John W. Krahn" wrote:
>
> HEISERER DANIEL wrote:
> >
> > Assume I have an array:
> >
> > @T=("a","b","c","d",......);
> >
> > I want to split (unzip) this array into two arrays:
> >
> > @T1=("a","c",......);
> > @T2=("b","d",.....);
> >
> > How is it done (I mean the cool way ;-), not some loops)?
>
> $ perl -e'
> @T = qw/a b c d e f g h/;
> print "@T\n";
> push @{ --$| ? \@T1 : \@T2 }, $_ for @T;
> print "@T1\n@T2\n";
> '
> a b c d e f g h
> a c e g
> b d f h
That was the "cool" unzip, what about bringing two lists together
with mixed elements and not concatted?
The zip?
@T3=($T1[0],$T2[0],$T1[1],$T2[1],$T1[2],....);
thanx,
daniel
--------------9377734B5A378DEA475EB428
Content-Type: text/x-vcard; charset=us-ascii;
name="daniel.heiserer.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for HEISERER DANIEL
Content-Disposition: attachment;
filename="daniel.heiserer.vcf"
begin:vcard
n:Daniel;Heiserer,
tel;fax:41696
tel;home:1409782
tel;work:21187
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:daniel.heiserer@bmw.de
x-mozilla-cpt:;-3136
fn:Heiserer, Daniel
end:vcard
--------------9377734B5A378DEA475EB428--
------------------------------
Date: Fri, 04 Oct 2002 15:41:44 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: unzip/zip an array
Message-Id: <3d9db552.2185846661@news.cis.dfn.de>
On Fri, 04 Oct 2002 16:58:19 +0200, HEISERER DANIEL
<daniel.heiserer@bmw.de> wrote:
>This is a multi-part message in MIME format.
Don't do that, Usenet is a text-only medium.
,
>Assume I have an array:
>
>@T=("a","b","c","d",......);
>
>I want to split (unzip) this array into two arrays:
>
>@T1=("a","c",......);
>@T2=("b","d",.....);
Here's one way, but it assumes that the "keys"
or array elements 0,2,4,6 etc, are unique.
#!perl
use warnings;
use strict;
my @T = qw/a b c d e f g h i j k l m n o p/;
my %hash = @T;
my @T1 = sort(keys %hash);
my @T2 = sort(values %hash);
print join "\t",@T1,"\n";
print join "\t",@T2,"\n";
__END__
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Fri, 04 Oct 2002 15:47:51 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: unzip/zip an array
Message-Id: <3D9DB822.19E73F02@acm.org>
HEISERER DANIEL wrote:
>
> "John W. Krahn" wrote:
> >
> > HEISERER DANIEL wrote:
> > >
> > > Assume I have an array:
> > >
> > > @T=("a","b","c","d",......);
> > >
> > > I want to split (unzip) this array into two arrays:
> > >
> > > @T1=("a","c",......);
> > > @T2=("b","d",.....);
> > >
> > > How is it done (I mean the cool way ;-), not some loops)?
> >
> > $ perl -e'
> > @T = qw/a b c d e f g h/;
> > print "@T\n";
> > push @{ --$| ? \@T1 : \@T2 }, $_ for @T;
> > print "@T1\n@T2\n";
> > '
> > a b c d e f g h
> > a c e g
> > b d f h
>
> That was the "cool" unzip, what about bringing two lists together
> with mixed elements and not concatted?
> The zip?
>
> @T3=($T1[0],$T2[0],$T1[1],$T2[1],$T1[2],....);
push @T3, shift @T1, shift @T2 while @T1, @T2;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 04 Oct 2002 17:46:41 +0200
From: HEISERER DANIEL <daniel.heiserer@bmw.de>
Subject: Re: unzip/zip an array
Message-Id: <3D9DB7E1.7374551F@bmw.de>
This is a multi-part message in MIME format.
--------------02750823CB70105721B8E446
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Helgi Briem wrote:
>
> On Fri, 04 Oct 2002 16:58:19 +0200, HEISERER DANIEL
> <daniel.heiserer@bmw.de> wrote:
>
> >This is a multi-part message in MIME format.
>
> Don't do that, Usenet is a text-only medium.
>
how can I turn it off? (I use netscape on linux)
,
> >Assume I have an array:
> >
> >@T=("a","b","c","d",......);
> >
> >I want to split (unzip) this array into two arrays:
> >
> >@T1=("a","c",......);
> >@T2=("b","d",.....);
>
> Here's one way, but it assumes that the "keys"
> or array elements 0,2,4,6 etc, are unique.
>
> #!perl
> use warnings;
> use strict;
> my @T = qw/a b c d e f g h i j k l m n o p/;
> my %hash = @T;
>
> my @T1 = sort(keys %hash);
> my @T2 = sort(values %hash);
>
> print join "\t",@T1,"\n";
> print join "\t",@T2,"\n";
> __END__
> --
> Regards, Helgi Briem
> helgi AT decode DOT is
>
> A: Top posting
> Q: What is the most irritating thing on Usenet?
> - "Gordon" on apihna
--
Mit freundlichen Gruessen
Daniel Heiserer
--------------------------------------------------------------
Dipl.-Phys. Daniel Heiserer, BMW AG, Knorrstrasse 147, 80788 Muenchen
Abteilung EK-212
Tel.: 089-382-21187, Fax.: 089-382-42820
mailto:daniel.heiserer@bmw.de
--------------02750823CB70105721B8E446
Content-Type: text/x-vcard; charset=us-ascii;
name="daniel.heiserer.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for HEISERER DANIEL
Content-Disposition: attachment;
filename="daniel.heiserer.vcf"
begin:vcard
n:Daniel;Heiserer,
tel;fax:41696
tel;home:1409782
tel;work:21187
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:daniel.heiserer@bmw.de
x-mozilla-cpt:;-3136
fn:Heiserer, Daniel
end:vcard
--------------02750823CB70105721B8E446--
------------------------------
Date: Fri, 04 Oct 2002 15:56:05 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: unzip/zip an array
Message-Id: <3D9DBA10.F9CD7039@acm.org>
HEISERER DANIEL wrote:
>
> Helgi Briem wrote:
> >
> > On Fri, 04 Oct 2002 16:58:19 +0200, HEISERER DANIEL
> > <daniel.heiserer@bmw.de> wrote:
> >
> > >This is a multi-part message in MIME format.
> >
> > Don't do that, Usenet is a text-only medium.
> >
>
> how can I turn it off? (I use netscape on linux)
From the menu:
Edit | Preferences | Mail & Newsgroups | Identity | [x] Attach my personal card to messages
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 04 Oct 2002 16:57:11 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: unzip/zip an array
Message-Id: <3D9DBA57.1E303602@oracle.com>
HEISERER DANIEL wrote:
> Hi,
> Assume I have an array:
>
> @T=("a","b","c","d",......);
>
> I want to split (unzip) this array into two arrays:
>
> @T1=("a","c",......);
> @T2=("b","d",.....);
>
> How is it done (I mean the cool way ;-), not some loops)?
>
> Once I have @T1 and @T2 how can I form (zip) them togehter
> into @T again?
>
> thanks, daniel
Assuming these values and that you want your arrays T1 and T2 to be
sorted alphabetically too, assign your array to a hash then you can
extract the values and keys of the hash
@T = qw/a b c d e f g h/;
%hashT=@T;
@T1=sort keys(%hashT);
@T2=sort values(%hashT);
Warning: if your original elements are not alphabetically sorted and you
wish to maintain the order of the elements as in the original array, use
a different method. If you don't care about the order of the elements,
skip the sort keyword in both instances.
To go the other way
@hashT{@T1)=@T2; # assign all the elements of T2 to key values in T1
@T=%hashT; # copy the key,value,key,value,key,value ... values to a
single array. (perl will know what to do!)
Graham Wood
------------------------------
Date: 04 Oct 2002 11:08:07 -0500
From: Joe Halpin <jhalpin@nortelnetworks.com_.nospam>
Subject: Re: unzip/zip an array
Message-Id: <yxs7n0pumbko.fsf@nortelnetworks.com_.nospam>
HEISERER DANIEL <daniel.heiserer@bmw.de> writes:
> This is a multi-part message in MIME format.
> --------------02750823CB70105721B8E446
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
>
> Helgi Briem wrote:
> >
> > On Fri, 04 Oct 2002 16:58:19 +0200, HEISERER DANIEL
> > <daniel.heiserer@bmw.de> wrote:
> >
> > >This is a multi-part message in MIME format.
> >
> > Don't do that, Usenet is a text-only medium.
>
> how can I turn it off? (I use netscape on linux)
Edit -> Preferences -> Mail & Newsgroups -> Formatting. Then check "Use
the plain text editor to compose messages".
You might also need to do Edit -> Preferences -> Identity, and uncheck
"Attache my personal card to messages".
This is for Netscape 4.x. It might be a little different if you're
using a later version, but that's the idea.
Joe
------------------------------
Date: 4 Oct 2002 16:30:53 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: unzip/zip an array
Message-Id: <ankfnt$sev$1@nets3.rz.RWTH-Aachen.DE>
Also sprach John W. Krahn:
> HEISERER DANIEL wrote:
>> @T=("a","b","c","d",......);
>>
>> I want to split (unzip) this array into two arrays:
>>
>> @T1=("a","c",......);
>> @T2=("b","d",.....);
> $ perl -e'
> @T = qw/a b c d e f g h/;
> print "@T\n";
> push @{ --$| ? \@T1 : \@T2 }, $_ for @T;
> print "@T1\n@T2\n";
> '
Heh, that must be the weirdest use of $| I have ever seen. :-) Only
problem is with an uneven number of elements in @T. Then you basically
reverse your autoflush settings. Therefore:
push @{ ++$i % 2 ? \@T1 : \@T2 }, $_ for @T;
Of course, this has the disadvantage of being pretty easy to understand.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Fri, 04 Oct 2002 13:59:48 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: unzip/zip an array
Message-Id: <3D9DD714.3011C3A1@earthlink.net>
Tassilo v. Parseval wrote:
>
> Also sprach John W. Krahn:
>
> > HEISERER DANIEL wrote:
>
> >> @T=("a","b","c","d",......);
> >>
> >> I want to split (unzip) this array into two arrays:
> >>
> >> @T1=("a","c",......);
> >> @T2=("b","d",.....);
>
> > $ perl -e'
> > @T = qw/a b c d e f g h/;
> > print "@T\n";
> > push @{ --$| ? \@T1 : \@T2 }, $_ for @T;
> > print "@T1\n@T2\n";
> > '
>
> Heh, that must be the weirdest use of $| I have ever seen.
I used to have this JAPH as my signature:
tr/`/ /, s/.//, print "@{[map --$| ? ucfirst lc : lc, split]}\n"
for pack u, pack 'H*', ab5cf4021bafd28972030972b00a218eb9720000;
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Fri, 04 Oct 2002 15:27:41 GMT
From: "pippobaccello" <defalco@hotmail.com>
Subject: webmail & strange characters
Message-Id: <Nrin9.48873$e31.1058701@twister2.libero.it>
I use a webmail (openwebmail).
When I send or receive mails with characters with accents or apostrophes I
get strange characters instead of the right ones.
s.o. Linux RH73
locale it_IT@euro
any hint?
tia
marco
------------------------------
Date: Fri, 4 Oct 2002 15:25:52 +0100
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: Win32::Console
Message-Id: <ank8op$kbb$1@newshost.mot.com>
"Cyril Scetbon" <externe.scetbon@francetelecom.com> wrote in message
news:3D9D761C.F359A97F@francetelecom.com...
Try this:
use Win32::Console;
$console=new Win32::Console;
$console->Size(80,50);
$console->Display();
$console->Attr($BG_BLUE|$FG_WHITE);
$console->Write("JUST A TEST\n\nPress <return>");
<>;
$console->Free;
it works for me.
when you call Size function a scroll appears on the right cause height
is updated.
-=-=-=-
Well, it works, of sorts.
Unfortunately, non of my print commands show up, and the background is still
black, but the text is in white on blue.
I have cheated by using:
system ("color 17");
system ("title My Title");
Which works, and gives me what I want, still allowing all my print commands
to work.
I just need to be able to resize the window, now. Anyone know how?
Thanks.
R.
------------------------------
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 3915
***************************************