RE: Joining variables
This wouldn't be homework by any chance??? -Original Message- From: Diego Riaño [mailto:[EMAIL PROTECTED]] Sent: 27 June 2001 13:59 To: [EMAIL PROTECTED] Subject: Joining variables Hi Perl guys I have another problem: I have three variables working: $var1 $var2 #and $var3 I want to join these three variables in a new one, with some formar, something like that: $newvar will be $var1-$var2-$var3 for example if: $var1=2000 $var2=08 #and $var3=15 then $newvar=2000-08-15 I hope someone can help me Thanks in advances DiegoM --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system.
Re: Joining variables
On Wed, Jun 27, 2001 at 02:07:22PM +0100, Pierre Smolarek wrote: $newvar = $var1.-.$var2.-.$var3; or $newvar = $var1-$var2-$var3;
Re: Joining variables
$newvar = $var1.-.$var2.-.$var3; - Original Message - From: John Edwards [EMAIL PROTECTED] To: 'Diego Riaño' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, June 27, 2001 2:01 PM Subject: RE: Joining variables This wouldn't be homework by any chance??? -Original Message- From: Diego Riaño [mailto:[EMAIL PROTECTED]] Sent: 27 June 2001 13:59 To: [EMAIL PROTECTED] Subject: Joining variables Hi Perl guys I have another problem: I have three variables working: $var1 $var2 #and $var3 I want to join these three variables in a new one, with some formar, something like that: $newvar will be $var1-$var2-$var3 for example if: $var1=2000 $var2=08 #and $var3=15 then $newvar=2000-08-15 I hope someone can help me Thanks in advances DiegoM --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system.
Re: Joining variables
On Wed, Jun 27, 2001 at 02:07:22PM +0100, Pierre Smolarek wrote: $newvar = $var1.-.$var2.-.$var3; or $newvar = $var1-$var2-$var3; or $concat = '-'; $newvar .= $var1; $newvar .= $concat; $newvar .= $var2; $newvar .= $concat; $newvar .= $var3; dude, you should really look this up in a book.. its pre-basic perl
Re: Joining variables
On 27 Jun 2001 14:37:14 +0100, Pierre Smolarek wrote: On Wed, Jun 27, 2001 at 02:07:22PM +0100, Pierre Smolarek wrote: $newvar = $var1.-.$var2.-.$var3; or $newvar = $var1-$var2-$var3; or $concat = '-'; $newvar .= $var1; $newvar .= $concat; $newvar .= $var2; $newvar .= $concat; $newvar .= $var3; dude, you should really look this up in a book.. its pre-basic perl or $newvar = join -, ($var1, $var2, $var3); TMTOWTDI -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167 Wibble.
Re: Joining variables
On 27 Jun 2001 10:06:28 -0400, Chas Owens wrote: On 27 Jun 2001 14:37:14 +0100, Pierre Smolarek wrote: On Wed, Jun 27, 2001 at 02:07:22PM +0100, Pierre Smolarek wrote: $newvar = $var1.-.$var2.-.$var3; or $newvar = $var1-$var2-$var3; or $concat = '-'; $newvar .= $var1; $newvar .= $concat; $newvar .= $var2; $newvar .= $concat; $newvar .= $var3; dude, you should really look this up in a book.. its pre-basic perl or $newvar = join -, ($var1, $var2, $var3); TMTOWTDI -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167 Wibble. or $newvar='';$newvar .= $_- foreach ($var1, $var2, $var3); chop $newvar; or $newvar = sprintf %04d-%02d-%02d, $var1, $var2, $var3; or $newvar =~ s/.*/$var1-$var2-$var3/; I think I need a life. -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167 Kallisti!
Re: Joining variables
Just to make it longwinded: my $stuff = { $var1 = - , $var2 = - , $var3 = - }; my $newvar = ; $newvar .= $_$stuff-{$_} foreach keys %{ $stuff }; At 11:45 27.06.2001 -0400, Chas Owens wrote: On 27 Jun 2001 10:06:28 -0400, Chas Owens wrote: On 27 Jun 2001 14:37:14 +0100, Pierre Smolarek wrote: On Wed, Jun 27, 2001 at 02:07:22PM +0100, Pierre Smolarek wrote: $newvar = $var1.-.$var2.-.$var3; or $newvar = $var1-$var2-$var3; or $concat = '-'; $newvar .= $var1; $newvar .= $concat; $newvar .= $var2; $newvar .= $concat; $newvar .= $var3; dude, you should really look this up in a book.. its pre-basic perl or $newvar = join -, ($var1, $var2, $var3); TMTOWTDI -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167 Wibble. or $newvar='';$newvar .= $_- foreach ($var1, $var2, $var3); chop $newvar; or $newvar = sprintf %04d-%02d-%02d, $var1, $var2, $var3; or $newvar =~ s/.*/$var1-$var2-$var3/; I think I need a life. -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167 Kallisti! Aaron Craig Programming iSoftitler.com
Re: Joining variables
So we have: $newvar = $var1.-.$var2.-.$var3; $newvar = $var1-$var2-$var3; $concat = '-'; $newvar .= $var1; $newvar .= $concat; $newvar .= $var2; $newvar .= $concat; $newvar .= $var3; $newvar = join -, ($var1, $var2, $var3); $newvar = join '', ($var1, '-', $var2, '-', $var3); #new varient $newvar='';$newvar .= $_- foreach ($var1, $var2, $var3); chop $newvar; $newvar = sprintf %04d-%02d-%02d, $var1, $var2, $var3; $newvar =~ s/.*/$var1-$var2-$var3/; Does this answer your question grin /? Anybody else want to add a few ways? I think I am tapped. -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167 Kallisti!
Re: Joining variables
hahahahaha # This one has already been said, but hey.. thought i would make a bigger mess of it my ($newvar); my @new = ($var1,$cat,$var2,$cat,$var3); foreach (@new){ $newvar .= $_; } #or # once again, already said, just making it obvious my @new = ($var1,$var2,$var3); $newvar = join(-,@new); #or even a bigger mess of the above. my (@new); push(@new, $var1); push(@new, $var2); push(@new, $var3); $newvar = join(-,@new); - Original Message - From: Chas Owens [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 27, 2001 5:39 PM Subject: Re: Joining variables So we have: $newvar = $var1.-.$var2.-.$var3; $newvar = $var1-$var2-$var3; $concat = '-'; $newvar .= $var1; $newvar .= $concat; $newvar .= $var2; $newvar .= $concat; $newvar .= $var3; $newvar = join -, ($var1, $var2, $var3); $newvar = join '', ($var1, '-', $var2, '-', $var3); #new varient $newvar='';$newvar .= $_- foreach ($var1, $var2, $var3); chop $newvar; $newvar = sprintf %04d-%02d-%02d, $var1, $var2, $var3; $newvar =~ s/.*/$var1-$var2-$var3/; Does this answer your question grin /? Anybody else want to add a few ways? I think I am tapped. -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167 Kallisti!
Re: Joining variables
the obvious proof i have too much time: for(join'',map{$_.=$:}@{[qw(2000 05 08)]}){s/\s//gchopprint} Jos - Original Message - From: Chas Owens [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 27, 2001 6:39 PM Subject: Re: Joining variables So we have: $newvar = $var1.-.$var2.-.$var3; $newvar = $var1-$var2-$var3; $concat = '-'; $newvar .= $var1; $newvar .= $concat; $newvar .= $var2; $newvar .= $concat; $newvar .= $var3; $newvar = join -, ($var1, $var2, $var3); $newvar = join '', ($var1, '-', $var2, '-', $var3); #new varient $newvar='';$newvar .= $_- foreach ($var1, $var2, $var3); chop $newvar; $newvar = sprintf %04d-%02d-%02d, $var1, $var2, $var3; $newvar =~ s/.*/$var1-$var2-$var3/; Does this answer your question grin /? Anybody else want to add a few ways? I think I am tapped. -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167 Kallisti!
Re: Joining variables
On 27 Jun 2001 19:56:49 +0200, Jos I. Boumans wrote: the obvious proof i have too much time: for(join'',map{$_.=$:}@{[qw(2000 05 08)]}){s/\s//gchopprint} Jos snip / Okay, I think you win. Please let me know if my attempt at an explaination of your abomination (modified slightly to be closer to the rest of the other answers already in thread) is incorrect in any way. code #!/usr/bin/perl -w use strict; my $var1 = '2001'; my $var2 = 06; my $var3 = 27; my $newvar; # $: is (by default) \n- for( #sets $_ to the value of the join below join '', #join every element of array created by map #with nothing as seperator map{$_ .= $:} #take every element of array built below #and append $: ( \n-) @{#dereference the arrayref about to be created [$var1, $var2, $var3] #create an array ref to an array containing vars }) { #end of for loop declaration s/\s//g#remove all whitespace from $_ (gets rid of the # \ns from the map) #if substitute is successful then chop #remove the last - from $_ #if chop is successful then ($newvar = $_) #assign date to $newvar } #end of for print $newvar\n; /code I feel dirty now. -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167
Re: Joining variables
*applauds* very good... no need to feel dirty.. just feel that you have WAY too much spare time trying to unobfuscate what i wrote =) regards, Jos - Original Message - From: Chas Owens [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 27, 2001 8:42 PM Subject: Re: Joining variables On 27 Jun 2001 19:56:49 +0200, Jos I. Boumans wrote: the obvious proof i have too much time: for(join'',map{$_.=$:}@{[qw(2000 05 08)]}){s/\s//gchopprint} Jos snip / Okay, I think you win. Please let me know if my attempt at an explaination of your abomination (modified slightly to be closer to the rest of the other answers already in thread) is incorrect in any way. code #!/usr/bin/perl -w use strict; my $var1 = '2001'; my $var2 = 06; my $var3 = 27; my $newvar; # $: is (by default) \n- for( #sets $_ to the value of the join below join '', #join every element of array created by map #with nothing as seperator map{$_ .= $:} #take every element of array built below #and append $: ( \n-) @{#dereference the arrayref about to be created [$var1, $var2, $var3] #create an array ref to an array containing vars }) { #end of for loop declaration s/\s//g#remove all whitespace from $_ (gets rid of the # \ns from the map) #if substitute is successful then chop #remove the last - from $_ #if chop is successful then ($newvar = $_) #assign date to $newvar } #end of for print $newvar\n; /code I feel dirty now. -- Today is Pungenday, the 32nd day of Confusion in the YOLD 3167