[28349] in Perl-Users-Digest
Perl-Users Digest, Issue: 9713 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 11 18:05:53 2006
Date: Mon, 11 Sep 2006 15:05:08 -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 Mon, 11 Sep 2006 Volume: 10 Number: 9713
Today's topics:
Attribute Parameter Problem with bind_param( ) pnstarr@gmail.com
Re: Attribute Parameter Problem with bind_param( ) <mritty@gmail.com>
Re: Attribute Parameter Problem with bind_param( ) xhoster@gmail.com
Re: Attribute Parameter Problem with bind_param( ) <john@castleamber.com>
Re: Attribute Parameter Problem with bind_param( ) pnstarr@gmail.com
Re: Attribute Parameter Problem with bind_param( ) pnstarr@gmail.com
Re: Attribute Parameter Problem with bind_param( ) <tadmc@augustmail.com>
Re: converting vba to perl without win32::ole <darthmullet67@hotmail.com>
Re: converting vba to perl without win32::ole <daveandniki@ntlworld.com>
Re: converting vba to perl without win32::ole <darthmullet67@hotmail.com>
Re: converting vba to perl without win32::ole <daveandniki@ntlworld.com>
Re: gah! <jl_post@hotmail.com>
Re: Hash slice from a hash reference? <roblund@gmail.com>
Re: Hash slice from a hash reference? <john@castleamber.com>
Help with delete an element in array <pradeep.bg@gmail.com>
Re: Help with delete an element in array <David.Squire@no.spam.from.here.au>
Re: Help with delete an element in array krakle@visto.com
Re: Help with delete an element in array <David.Squire@no.spam.from.here.au>
Re: Help with delete an element in array <pradeep.bg@gmail.com>
Re: Help with delete an element in array <David.Squire@no.spam.from.here.au>
Re: Help with delete an element in array <David.Squire@no.spam.from.here.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Sep 2006 10:10:05 -0700
From: pnstarr@gmail.com
Subject: Attribute Parameter Problem with bind_param( )
Message-Id: <1157994605.896799.192150@p79g2000cwp.googlegroups.com>
Hi everybody,
I've got a script that works perfectly when called from the command
prompt. It collects data from online databases, processes it, and
prints. I'm trying to use it in a web site, where the input is from an
html form. But not all the data I want is printed into the newly
created html page and the error log says that there is an attribute
parameter problem in one of the methods called in the script.
Here is the error from the error log:
[error] [client 127.0.0.1] DBI::st=HASH(0x89628a4)->bind_param(...):
attribute parameter '12' is not a hash ref at
/home/pns7/src/ensembl/modules//Bio/EnsEMBL/DBSQL/SliceAdaptor.pm line
246.
Here is the SliceAdaptor.pm code line:
246 $sth->bind_param(1, "$seq_region_name", SQL_VARCHAR);
And bind_param( ) evidently has the following definitions according to
O'Reilly's Programming the Perl DBI:
bind_param($p_num, $bind_value)
bind_param($p_num, $bind_value, \%attr)
bind_param($p_num, $bind_value, $bind_type)
SQL_VARCHAR does have the value '12' and is not a hash reference, but
why does this matter since SQL_VARCHAR is a bind_type variable?
Moreover, why does the method fail here but work when the script is run
from the command prompt?
Can somebody please help? Thanks,
Peter
------------------------------
Date: 11 Sep 2006 10:23:16 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Attribute Parameter Problem with bind_param( )
Message-Id: <1157995396.072651.298980@m73g2000cwd.googlegroups.com>
pnstarr@gmail.com wrote:
> I've got a script that works perfectly when called from the command
> prompt. It collects data from online databases, processes it, and
> prints. I'm trying to use it in a web site, where the input is from an
> html form. But not all the data I want is printed into the newly
> created html page and the error log says that there is an attribute
> parameter problem in one of the methods called in the script.
>
> Here is the error from the error log:
>
> [error] [client 127.0.0.1] DBI::st=HASH(0x89628a4)->bind_param(...):
> attribute parameter '12' is not a hash ref at
> /home/pns7/src/ensembl/modules//Bio/EnsEMBL/DBSQL/SliceAdaptor.pm line
> 246.
>
> Here is the SliceAdaptor.pm code line:
>
> 246 $sth->bind_param(1, "$seq_region_name", SQL_VARCHAR);
Please read:
perldoc -q quoting
> And bind_param( ) evidently has the following definitions according to
> O'Reilly's Programming the Perl DBI:
> bind_param($p_num, $bind_value)
> bind_param($p_num, $bind_value, \%attr)
> bind_param($p_num, $bind_value, $bind_type)
>
> SQL_VARCHAR does have the value '12' and is not a hash reference, but
> why does this matter since SQL_VARCHAR is a bind_type variable?
> Moreover, why does the method fail here but work when the script is run
> from the command prompt?
How confident are you that your command-line and web environments are
identical? Try printing the value of $DBI::VERSION in your script, and
seeing if you get the same results in both environments. Then try
$DBD::Foo::VERSION (where 'Foo' is your driver module).
Out of curiousity, why are you providing that value to bind_param in
the first place? What benefit is it giving you?
Paul Lalli
------------------------------
Date: 11 Sep 2006 17:27:34 GMT
From: xhoster@gmail.com
Subject: Re: Attribute Parameter Problem with bind_param( )
Message-Id: <20060911132818.756$kr@newsreader.com>
pnstarr@gmail.com wrote:
> Hi everybody,
>
> I've got a script that works perfectly when called from the command
> prompt. It collects data from online databases, processes it, and
> prints. I'm trying to use it in a web site, where the input is from an
> html form. But not all the data I want is printed into the newly
> created html page and the error log says that there is an attribute
> parameter problem in one of the methods called in the script.
>
> Here is the error from the error log:
>
> [error] [client 127.0.0.1] DBI::st=HASH(0x89628a4)->bind_param(...):
> attribute parameter '12' is not a hash ref at
> /home/pns7/src/ensembl/modules//Bio/EnsEMBL/DBSQL/SliceAdaptor.pm line
> 246.
>
> Here is the SliceAdaptor.pm code line:
>
> 246 $sth->bind_param(1, "$seq_region_name", SQL_VARCHAR);
>
> And bind_param( ) evidently has the following definitions according to
> O'Reilly's Programming the Perl DBI:
> bind_param($p_num, $bind_value)
> bind_param($p_num, $bind_value, \%attr)
> bind_param($p_num, $bind_value, $bind_type)
>
> SQL_VARCHAR does have the value '12' and is not a hash reference, but
> why does this matter since SQL_VARCHAR is a bind_type variable?
What version of DBI are you using? Which DBD are you using? What version?
> Moreover, why does the method fail here but work when the script is run
> from the command prompt?
Are you using the same versions of everything (Perl, DBI, DBD) between
the two situations?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 11 Sep 2006 19:20:23 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Attribute Parameter Problem with bind_param( )
Message-Id: <Xns983B91DD2939Ccastleamber@130.133.1.4>
"Paul Lalli" <mritty@gmail.com> wrote:
> Out of curiousity, why are you providing that value to bind_param in
> the first place? What benefit is it giving you?
Not sure if it holds here, but see:
http://johnbokma.com/mexit/2006/03/12/index-exceeds-900-bytes.html
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: 11 Sep 2006 12:54:30 -0700
From: pnstarr@gmail.com
Subject: Re: Attribute Parameter Problem with bind_param( )
Message-Id: <1158004470.417867.146610@d34g2000cwd.googlegroups.com>
Much thanks. I'm using the same DBI version on both, 1.52. However, I
get an error when trying to print $DBD::Foo::VERSION. The error is "a
use of unitialized value in concatenation (.) or string. I've tried to
locate DBD::Foo in my directories and I can't. So I'm going to see if
I need to install the DBD::MySQL module. But I don't think I should
need to do that since the script already works when run from command
prompt.
Paul Lalli wrote:
> pnstarr@gmail.com wrote:
> > I've got a script that works perfectly when called from the command
> > prompt. It collects data from online databases, processes it, and
> > prints. I'm trying to use it in a web site, where the input is from an
> > html form. But not all the data I want is printed into the newly
> > created html page and the error log says that there is an attribute
> > parameter problem in one of the methods called in the script.
> >
> > Here is the error from the error log:
> >
> > [error] [client 127.0.0.1] DBI::st=HASH(0x89628a4)->bind_param(...):
> > attribute parameter '12' is not a hash ref at
> > /home/pns7/src/ensembl/modules//Bio/EnsEMBL/DBSQL/SliceAdaptor.pm line
> > 246.
> >
> > Here is the SliceAdaptor.pm code line:
> >
> > 246 $sth->bind_param(1, "$seq_region_name", SQL_VARCHAR);
>
> Please read:
> perldoc -q quoting
>
>
> > And bind_param( ) evidently has the following definitions according to
> > O'Reilly's Programming the Perl DBI:
> > bind_param($p_num, $bind_value)
> > bind_param($p_num, $bind_value, \%attr)
> > bind_param($p_num, $bind_value, $bind_type)
> >
> > SQL_VARCHAR does have the value '12' and is not a hash reference, but
> > why does this matter since SQL_VARCHAR is a bind_type variable?
> > Moreover, why does the method fail here but work when the script is run
> > from the command prompt?
>
> How confident are you that your command-line and web environments are
> identical? Try printing the value of $DBI::VERSION in your script, and
> seeing if you get the same results in both environments. Then try
> $DBD::Foo::VERSION (where 'Foo' is your driver module).
>
> Out of curiousity, why are you providing that value to bind_param in
> the first place? What benefit is it giving you?
>
> Paul Lalli
------------------------------
Date: 11 Sep 2006 12:56:51 -0700
From: pnstarr@gmail.com
Subject: Re: Attribute Parameter Problem with bind_param( )
Message-Id: <1158004611.223051.319310@e3g2000cwe.googlegroups.com>
Well, the bind_param( ) is being used in some BioPerl module. I didn't
write the code. I did try, however, to delete the data type variable,
but I got an even more inscrutable error message.
John Bokma wrote:
> "Paul Lalli" <mritty@gmail.com> wrote:
>
> > Out of curiousity, why are you providing that value to bind_param in
> > the first place? What benefit is it giving you?
>
> Not sure if it holds here, but see:
> http://johnbokma.com/mexit/2006/03/12/index-exceeds-900-bytes.html
>
> --
> John Experienced Perl programmer: http://castleamber.com/
>
> Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: Mon, 11 Sep 2006 16:00:27 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Attribute Parameter Problem with bind_param( )
Message-Id: <slrnegbjjb.n7q.tadmc@magna.augustmail.com>
[ Please stop top-posting! ]
pnstarr@gmail.com <pnstarr@gmail.com> wrote:
> Much thanks. I'm using the same DBI version on both, 1.52. However, I
> get an error when trying to print $DBD::Foo::VERSION.
> Paul Lalli wrote:
>> Then try
>> $DBD::Foo::VERSION (where 'Foo' is your driver module).
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 11 Sep 2006 08:06:12 -0700
From: "matt" <darthmullet67@hotmail.com>
Subject: Re: converting vba to perl without win32::ole
Message-Id: <1157987172.593233.314830@i42g2000cwa.googlegroups.com>
> I'm not sure why you refer to win32::ole, if you want to parse the VBA code
> using perl to automatically convert it, you can save it as a text file,
> (.vbs is just a plain text file).
Only reason I mentioned win32::ole was because I didn't want someone to
suggest that I use the ActiveState Perl Dev Kit and run the VBScript
converter tool. My main goal is to remove the memory hog Microsoft
products.
One other question I have is: "Will the global substitution after the
if stmt replace until the EOF or will it replace for the entire file?"
>if ($_ =~ /<R [,;)].*<R [,;)].*<R [,;)].*[0-9]+ [0-9]+ [0-9]/) {
> $_ =~ s/(\n\+pg,[0-9]+\n)(\+l)/ $2$1/g;
> &Subroutine;
>}
------------------------------
Date: Mon, 11 Sep 2006 17:37:55 +0200
From: "Dave" <daveandniki@ntlworld.com>
Subject: Re: converting vba to perl without win32::ole
Message-Id: <450582dc$0$25946$ba4acef3@news.orange.fr>
"matt" <darthmullet67@hotmail.com> wrote in message
news:1157987172.593233.314830@i42g2000cwa.googlegroups.com...
>> I'm not sure why you refer to win32::ole, if you want to parse the VBA
>> code
>> using perl to automatically convert it, you can save it as a text file,
>> (.vbs is just a plain text file).
>
> Only reason I mentioned win32::ole was because I didn't want someone to
> suggest that I use the ActiveState Perl Dev Kit and run the VBScript
> converter tool. My main goal is to remove the memory hog Microsoft
> products.
>
> One other question I have is: "Will the global substitution after the
> if stmt replace until the EOF or will it replace for the entire file?"
>>if ($_ =~ /<R [,;)].*<R [,;)].*<R [,;)].*[0-9]+ [0-9]+ [0-9]/) {
>> $_ =~ s/(\n\+pg,[0-9]+\n)(\+l)/ $2$1/g;
>> &Subroutine;
>>}
>
It will replace for the whole file, as does the original VBA code, I think -
Selection.HomeKey wdStory
resets to the beginning of the file.
However I'm not sure now that your searching and your Selection operations
are happening on the same thing...
Notably findText and FindandReplace are not standard methods in VBA. What
libraries are you using? What is Variable_class?
I think you need to provide fuller information.
------------------------------
Date: 11 Sep 2006 11:27:45 -0700
From: "matt" <darthmullet67@hotmail.com>
Subject: Re: converting vba to perl without win32::ole
Message-Id: <1157999265.300718.27220@p79g2000cwp.googlegroups.com>
> It will replace for the whole file, as does the original VBA code, I think -
> Selection.HomeKey wdStory
> resets to the beginning of the file.
Selection.HomeKey wdStory does reset to the beginning of the file and
the VBA code does replace for the whole file
> However I'm not sure now that your searching and your Selection operations
> are happening on the same thing...
>
> Notably findText and FindandReplace are not standard methods in VBA. What
> libraries are you using? What is Variable_class?
Sorry about the lack of information(definitely don't know VBA very
well, I am trying to fix someone elses mess) findText will search for a
string that is passed in and will highlight to the selection object the
next occurance. FindandReplace will search through the document for
the passed in string and replace it with the replacement string (uses
.Execute Replace:=wdReplaceAll)
How would I search for a string and once found do find and replaces
from that point on until EOF in perl?
Thanks for your help so far
------------------------------
Date: Mon, 11 Sep 2006 21:14:14 +0200
From: "Dave" <daveandniki@ntlworld.com>
Subject: Re: converting vba to perl without win32::ole
Message-Id: <4505b58b$0$27406$ba4acef3@news.orange.fr>
"matt" <darthmullet67@hotmail.com> wrote in message
news:1157999265.300718.27220@p79g2000cwp.googlegroups.com...
>> It will replace for the whole file, as does the original VBA code, I
>> think -
>> Selection.HomeKey wdStory
>> resets to the beginning of the file.
> Selection.HomeKey wdStory does reset to the beginning of the file and
> the VBA code does replace for the whole file
>
>> However I'm not sure now that your searching and your Selection
>> operations
>> are happening on the same thing...
>>
>> Notably findText and FindandReplace are not standard methods in VBA. What
>> libraries are you using? What is Variable_class?
> Sorry about the lack of information(definitely don't know VBA very
> well, I am trying to fix someone elses mess) findText will search for a
> string that is passed in and will highlight to the selection object the
> next occurance. FindandReplace will search through the document for
> the passed in string and replace it with the replacement string (uses
> .Execute Replace:=wdReplaceAll)
>
> How would I search for a string and once found do find and replaces
> from that point on until EOF in perl?
>
> Thanks for your help so far
>
You are probably looking for the \G modifier:
if ($_ =~ /<R [,;)].*<R [,;)].*<R [,;)].*[0-9]+ [0-9]+ [0-9]/) {
$_ =~ s/\G(\n\+pg,[0-9]+\n)(\+l)/ $2$1/g;
&Subroutine;
}
(untested)
------------------------------
Date: 11 Sep 2006 10:40:38 -0700
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: gah!
Message-Id: <1157996438.841271.294290@d34g2000cwd.googlegroups.com>
Don Corleone wrote:
>
> In a nutshell this is what i am trying to make the program do:
>
> 1. get a directory name (works ok)
> 2. Get a list of all the tif files in this directory (works ok)
> 3. perform a msdos file operation on each file returned
> by 2 above (doesnt work).
To be honest, saying that it "doesn't work" doesn't tell us much
about the nature of your error, especially since you're so vague about
the code you're using to accomplish what you want to do. In other
words, could you be more specific?
What'll really help us is if you post a short and complete working
program that we can run that reproduces your problem. Then it's
extremely likely that we'll find your error.
But until you do that, I'll ask: In step 2, did you use the
readdir() function? If you did, you may have unknowingly introduced a
very common bug that often appears alongside opendir() and readdir()
functions. Try reading "perldoc -f readdir" (pay particular attention
to the second paragraph) and see if that doesn't address your problem.
If that doesn't help, you'll most likely have to post a real working
program (preferably a small one) that demonstrates the problem.
I hope this helps.
-- Jean-Luc
------------------------------
Date: 11 Sep 2006 12:44:21 -0700
From: "alt.binaries.pictures.numismatics" <roblund@gmail.com>
Subject: Re: Hash slice from a hash reference?
Message-Id: <1158003861.708279.276440@m73g2000cwd.googlegroups.com>
John Bokma wrote:
> "Mark G." <nospam@thanksanyway.org> wrote:
>
> >
> > "Mark G." <nospam@thanksanyway.org> wrote:
> >> Good morning.
> >>
> >> I am trying to take a hash reference and obtain a slice
> >> of the underlying hash.
> >
> > And the winner is:
> >
> > @{$hashref}{'key01','key03'} = ('val01','val03');
>
> which you might want to write as:
>
> @{ $hashref }{ qw( key01 keyp3 ) } = qw( val01 val03 );
>
Slightly off topic, but in general, I think that hash slices make for
"unreadable" code. Sure, many of us know how to use them, and can
recognize them at the same time, but many many perl programmers really
have no idea how they work, and are utterly baffled by the syntax.
Especially in the case of two or three keys, it might be wiser to just
explicity assign the elements:
$hash->{key01} = 'val01';
$hash->{key02} = 'val02';
------------------------------
Date: 11 Sep 2006 20:35:15 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Hash slice from a hash reference?
Message-Id: <Xns983B9E8E297B5castleamber@130.133.1.4>
"alt.binaries.pictures.numismatics" <roblund@gmail.com> wrote:
> John Bokma wrote:
>> @{ $hashref }{ qw( key01 keyp3 ) } = qw( val01 val03 );
>
> Slightly off topic, but in general, I think that hash slices make for
> "unreadable" code. Sure, many of us know how to use them, and can
> recognize them at the same time, but many many perl programmers really
> have no idea how they work, and are utterly baffled by the syntax.
It's not that hard to learn the syntax, but I agree with:
> Especially in the case of two or three keys, it might be wiser to just
> explicity assign the elements:
>
> $hash->{key01} = 'val01';
> $hash->{key02} = 'val02';
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: 11 Sep 2006 11:51:42 -0700
From: "Deepu" <pradeep.bg@gmail.com>
Subject: Help with delete an element in array
Message-Id: <1158000702.115458.323150@b28g2000cwb.googlegroups.com>
Hi All,
I have $key = "SA-SB-SC-SD" separated by '-'
I am trying to delete SC and the output should be
$test="SA-SB-SD".
But when I do as shown below, the output generated is
$test="SA-SB--SD". I am not getting the reason for getting extra
'-'.
$key="SA-SB-SC-SD";
@test=split(/-/,$key);
Delete $test[1];
$test=join '-',@test;
Print $test;
Thanks for the time.
------------------------------
Date: Mon, 11 Sep 2006 19:56:30 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Help with delete an element in array
Message-Id: <ee4bgu$em2$1@gemini.csx.cam.ac.uk>
Deepu wrote:
> Hi All,
>
> I have $key = "SA-SB-SC-SD" separated by '-'
> I am trying to delete SC and the output should be
> $test="SA-SB-SD".
>
> But when I do as shown below, the output generated is
> $test="SA-SB--SD". I am not getting the reason for getting extra
> '-'.
>
>
> $key="SA-SB-SC-SD";
>
> @test=split(/-/,$key);
>
> Delete $test[1];
>
> $test=join '-',@test;
>
> Print $test;
This won't compile, let alone being safe under "use strict;" and "use
warnings;". Please post your real code. Don't just type in nonsense.
DS
------------------------------
Date: 11 Sep 2006 11:57:57 -0700
From: krakle@visto.com
Subject: Re: Help with delete an element in array
Message-Id: <1158001077.863518.119010@d34g2000cwd.googlegroups.com>
Deepu wrote:
> Hi All,
>
> I have $key = "SA-SB-SC-SD" separated by '-'
> I am trying to delete SC and the output should be
> $test="SA-SB-SD".
$test =~ s/\-SC//g;
------------------------------
Date: Mon, 11 Sep 2006 20:01:26 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Help with delete an element in array
Message-Id: <ee4bq6$feu$1@gemini.csx.cam.ac.uk>
David Squire wrote:
> Deepu wrote:
>> Hi All,
>>
>> I have $key = "SA-SB-SC-SD" separated by '-'
>> I am trying to delete SC and the output should be
>> $test="SA-SB-SD".
>>
>> But when I do as shown below, the output generated is
>> $test="SA-SB--SD". I am not getting the reason for getting extra
>> '-'.
>>
>>
>> $key="SA-SB-SC-SD";
>>
>> @test=split(/-/,$key);
>>
>> Delete $test[1];
>>
>> $test=join '-',@test;
>>
>> Print $test;
>
> This won't compile, let alone being safe under "use strict;" and "use
> warnings;". Please post your real code. Don't just type in nonsense.
I'm feeling (a bit) generous. Reading the documentation for the Perl
function 'delete' will tell you what is going on - and point you in the
direction of the function you seem to want: splice.
perldoc -f delete
perldoc -f splice
DS
------------------------------
Date: 11 Sep 2006 12:11:23 -0700
From: "Deepu" <pradeep.bg@gmail.com>
Subject: Re: Help with delete an element in array
Message-Id: <1158001883.072204.205750@d34g2000cwd.googlegroups.com>
Thanks for the info. I used Splice now and it works.
I used:
#!/usr/bin/perl
my $key = "SA-SB-SC-SD";
my @test = split (/-/,$key);
splice(@test,1,1);
my $test = join '-',@test;
print $test;
David Squire wrote:
> David Squire wrote:
> > Deepu wrote:
> >> Hi All,
> >>
> >> I have $key = "SA-SB-SC-SD" separated by '-'
> >> I am trying to delete SC and the output should be
> >> $test="SA-SB-SD".
> >>
> >> But when I do as shown below, the output generated is
> >> $test="SA-SB--SD". I am not getting the reason for getting extra
> >> '-'.
> >>
> >>
> >> $key="SA-SB-SC-SD";
> >>
> >> @test=split(/-/,$key);
> >>
> >> Delete $test[1];
> >>
> >> $test=join '-',@test;
> >>
> >> Print $test;
> >
> > This won't compile, let alone being safe under "use strict;" and "use
> > warnings;". Please post your real code. Don't just type in nonsense.
>
> I'm feeling (a bit) generous. Reading the documentation for the Perl
> function 'delete' will tell you what is going on - and point you in the
> direction of the function you seem to want: splice.
>
> perldoc -f delete
> perldoc -f splice
>
>
> DS
------------------------------
Date: Mon, 11 Sep 2006 20:16:34 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Help with delete an element in array
Message-Id: <ee4cmi$hbs$1@gemini.csx.cam.ac.uk>
Deepu wrote:
[top--posting corrected. Please don't do that.]
> David Squire wrote:
>> David Squire wrote:
>>> Deepu wrote:
>>>> Hi All,
>>>>
>>>> I have $key = "SA-SB-SC-SD" separated by '-'
>>>> I am trying to delete SC and the output should be
>>>> $test="SA-SB-SD".
>>>>
>>>> But when I do as shown below, the output generated is
>>>> $test="SA-SB--SD". I am not getting the reason for getting extra
>>>> '-'.
>>>>
>>>>
>>>> $key="SA-SB-SC-SD";
>>>>
>>>> @test=split(/-/,$key);
>>>>
>>>> Delete $test[1];
>>>>
>>>> $test=join '-',@test;
>>>>
>>>> Print $test;
>>> This won't compile, let alone being safe under "use strict;" and "use
>>> warnings;". Please post your real code.
[snip]
>>
>> perldoc -f delete
>> perldoc -f splice
>>
>>
>> DS
>
> Thanks for the info. I used Splice now and it works.
Good. Please get into the habit of reading the documentation *before*
posting here.
> I used:
>
> #!/usr/bin/perl
>
missing:
use strict; # though your code is indeed now strict-safe. Thanks for that.
use warnings;
> my $key = "SA-SB-SC-SD";
no need for double-quotes here.
> my @test = split (/-/,$key);
> splice(@test,1,1);
> my $test = join '-',@test;
> print $test;
Just FYI, this will also work in your case:
my $pos_to_replace = 1;
$key =~ s/(([A-Z]{2}-){$pos_to_replace})[A-Z]{2}-/$1/;
DS
------------------------------
Date: Mon, 11 Sep 2006 20:22:47 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Help with delete an element in array
Message-Id: <ee4d28$i24$1@gemini.csx.cam.ac.uk>
David Squire wrote:
> Deepu wrote:
>
> > my $key = "SA-SB-SC-SD";
[snip]
>
> Just FYI, this will also work in your case:
>
> my $pos_to_replace = 1;
> $key =~ s/(([A-Z]{2}-){$pos_to_replace})[A-Z]{2}-/$1/;
Actually, no :( This will fail if you try to replace this last element
of $key.
DS
------------------------------
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 9713
***************************************