Ask a Question related to PERL Beginners, Design and Development.
-
Anthony J Segelhorst #1
array push
How come when I push a variable to an array it puts one whitespace before
the variables on all the lines except the first one? I would except all
the lines not to have the extra white space.
Is there an easier way to fill an array with a variable without using the
push?
$last printed out
TMR2,mpd_gw,50,w32-ix86,client
TMR2,mpd_gw,50,w32-ix86,client
TMR2,mpd_gw,50,w32-ix86,client
TMR2,mpd_gw,50,w32-ix86,client
@temparray printed out
TMR2,mpd_gw,50,w32-ix86,client
TMR2,mpd_gw,50,w32-ix86,client
TMR2,mpd_gw,50,w32-ix86,client
TMR2,mpd_gw,50,w32-ix86,client
Code:
if (something){
$last = "$tmrname,$gateway_hash{$gateway},$version,$interp ,$type\n";
#print "$last";
push(@temparray, $last);
}
@temparray = sort @temparray;
print "@temparray";
Anthony J Segelhorst
Enterprise Systems Management Team
Phone: 937-495-1876
Email: [email]ajs15@meadwestvaco.com[/email]
__________________________________________________ ______________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service.__________________________________________ _____________________
Note: Please update your email address for this user to reflect the
new MeadWestvaco Corporation. MeadWestvaco employee email addresses
are in the format of [email]user@MeadWestvaco.com[/email]
This electronic message contains information from MeadWestvaco
Corporation or subsidiary companies, which may be confidential,
privileged or otherwise protected from disclosure. The
information is intended to be used solely by the recipient(s)
named. If you are not an intended recipient, be aware that
any review, disclosure, copying, distribution or use of this
transmission or its contents is prohibited. If you have
received this transmission in error, please notify MeadWestvaco
immediately at [email]postmaster@MeadWestvaco.com[/email].
__________________________________________________ _____________________
Anthony J Segelhorst Guest
-
Push XML to FMS
Can FMS create an XML socket that listens for and accepts connections from external services? I know that FMS can create an XML socket and... -
Push URL
I am trying to create a URL push call to send a url that will open a browser and navigate to the url for all users in the room. Does anyone have any... -
Need a bit of a push...
OK, ive been given a brief to simulate a tank. Ie, a flexible track around several wheels that drives a tank across a terrain. Anyone know of... -
push
hey all, i know a little about flash, but my problem is that, i want to make a counter-strike cartoon, but I want to press a little button in the... -
[PHP] Array Push and Keys
On Thu, 28 Aug 2003 18:14:39 -0400, you wrote: Ahem. Count the brackets? :) (On a style point, your code would be easier to read for bugs... -
Tim #2
Re: array push
At 11:17 AM 1/26/04 -0500, you wrote:
Take the quotes off.>print "@temparray";
Tim Guest
-
Wolf Blaum #3
Re: array push
For Quality purpouses, Anthony J Segelhorst 's mail on Monday 26 January 2004
17:17 may have been monitored or recorded as:
..> How come when I push a variable to an array it puts one whitespace before
> the variables on all the lines except the first one? *I would except all
> the lines not to have the extra white space.Try print @temparay;> print "@temparray";
since you have a "\n" at the end of your array (btw: do you really want
that?) , your records are seperated by something when you print them.
print " " puts a space in between the eleent as a convienience for people who
dont have a "\n" at the end of their emelents.
hth, wolf
Wolf Blaum Guest
-
Anthony J Segelhorst #4
Re: array push
>For Quality purposes, Anthony J Segelhorst 's mail on Monday 26 January
2004>17:17 may have been monitored or recorded as:before> How come when I push a variable to an array it puts one whitespace...> the variables on all the lines except the first one? *I would except all
> the lines not to have the extra white space.> print "@temparray";>Try print @temparay;who>since you have a "\n" at the end of your array (btw: do you really want
>that?) , your records are seperated by something when you print them.
>print " " puts a space in between the eleent as a convienience for peopleprint @temparay;>dont have a "\n" at the end of their emelents.
This worked, thanks.
Anthony J Segelhorst
Enterprise Systems Management Team
Phone: 937-495-1876
Email: [email]ajs15@meadwestvaco.com[/email]
wolf blaum <blaum@uthscsa.edu>
01/26/2004 11:39 AM
To:
cc:
Subject: Re: array push
For Quality purpouses, Anthony J Segelhorst 's mail on Monday 26 January
2004
17:17 may have been monitored or recorded as:
before> How come when I push a variable to an array it puts one whitespace...> the variables on all the lines except the first one? *I would except all
> the lines not to have the extra white space.Try print @temparay;> print "@temparray";
since you have a "\n" at the end of your array (btw: do you really want
that?) , your records are seperated by something when you print them.
print " " puts a space in between the eleent as a convienience for people
who
dont have a "\n" at the end of their emelents.
hth, wolf
--
To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
__________________________________________________ ______________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service.__________________________________________ _____________________
__________________________________________________ ______________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service.__________________________________________ _____________________
Note: Please update your email address for this user to reflect the
new MeadWestvaco Corporation. MeadWestvaco employee email addresses
are in the format of [email]user@MeadWestvaco.com[/email]
This electronic message contains information from MeadWestvaco
Corporation or subsidiary companies, which may be confidential,
privileged or otherwise protected from disclosure. The
information is intended to be used solely by the recipient(s)
named. If you are not an intended recipient, be aware that
any review, disclosure, copying, distribution or use of this
transmission or its contents is prohibited. If you have
received this transmission in error, please notify MeadWestvaco
immediately at [email]postmaster@MeadWestvaco.com[/email].
__________________________________________________ _____________________
Anthony J Segelhorst Guest
-
Rob Dixon #5
Re: array push
Wolf Blaum wrote:
The right conclusion for the wrong reasons Wolf! The spaces are the result of>
> For Quality purpouses, Anthony J Segelhorst 's mail on Monday 26 January 2004
> 17:17 may have been monitored or recorded as:
>> ..> > How come when I push a variable to an array it puts one whitespace before
> > the variables on all the lines except the first one? I would except all
> > the lines not to have the extra white space.>> > print "@temparray";
> Try print @temparay;
>
> since you have a "\n" at the end of your array (btw: do you really want
> that?) , your records are seperated by something when you print them.
> print " " puts a space in between the eleent as a convienience for people who
> dont have a "\n" at the end of their emelents.
interpolating the array into a string, and the presence of a newline on each
array element is immaterial:
my @arr = ('A', 'B', 'C', 'D');
print "@arr\n";
print @arr, "\n";
**OUTPUT
A B C D
ABCD
In general, it's a bad idea to put variables inside double quotes unless know
what it means.
my $var = $value
is much more likely to be right than
my $var = "$value"
and the latter is very similar to adding zero to a numeric varibale.
Cheers,
Rob
Rob Dixon Guest
-
Wolf Blaum #6
Re: array push
For Quality purpouses, Rob Dixon 's mail on Tuesday 27 January 2004 00:30may
have been monitored or recorded as:
Hi Rob,> The right conclusion for the wrong reasons Wolf! The spaces are the result
> of interpolating the array into a string, and the presence of a newline on
> each array element is immaterial:
>
> my @arr = ('A', 'B', 'C', 'D');
> print "@arr\n";
> print @arr, "\n";
>
> **OUTPUT
>
> A B C D
> ABCD
well, maybe Im totally wrong here, but getting these results :
$last printed out
TMR2,mpd_gw,50,w32-ix86,client
TMR2,mpd_gw,50,w32-ix86,client
TMR2,mpd_gw,50,w32-ix86,client
TMR2,mpd_gw,50,w32-ix86,client
@temparray printed out
TMR2,mpd_gw,50,w32-ix86,client
*TMR2,mpd_gw,50,w32-ix86,client
*TMR2,mpd_gw,50,w32-ix86,client
*TMR2,mpd_gw,50,w32-ix86,client
*
from this code:
Code:
if (something){
$last = "$tmrname,$gateway_hash{$gateway},$version,$interp ,$type\n";
* * * * #print "$last";
* * * * push(@temparray, $last);
}
@temparray = sort @temparray;
print "@temparray";
Anthony asked, where the spaces came from, expecting the output of $last and
@temparray to be the same.
Of course, you are right about the interpolation used before the print : i
just meant to point out that the newlines AND the spaces in his print
"@temparray" are a result of the quotes used with print, and his attachment
of \n to $last before the push @temparray,$last - without making it to
complicated.
(Tim also hinted to $").
Or did I totaly miss something.
thx, wolf
Wolf Blaum Guest
-
Rob Dixon #7
Re: array push
Wolf Blaum wrote:
Yes. These are the values of each string before they are pushed onto the array>
> For Quality purpouses, Rob Dixon 's mail on Tuesday 27 January 2004 00:30 may
> have been monitored or recorded as:
>>> > The right conclusion for the wrong reasons Wolf! The spaces are the result
> > of interpolating the array into a string, and the presence of a newline on
> > each array element is immaterial:
> >
> > my @arr = ('A', 'B', 'C', 'D');
> > print "@arr\n";
> > print @arr, "\n";
> >
> > **OUTPUT
> >
> > A B C D
> > ABCD
> well, maybe Im totally wrong here, but getting these results :
>
> $last printed out
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
(In the order they are pushed but before they're sorted).
Didn't you mean to put spaces before the last three records? This will be the> @temparray printed out
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
result of
print @temparray;
which is the same as
print $temparray[0], $temparray[1], $temparray[2], $temparray[3];
not
print "@temparray";
which is the same as
print join ' ', @temparray;
Thew newlines in the output are there because they were in the original> from this code:
>
> Code:
> if (something){
> $last = "$tmrname,$gateway_hash{$gateway},$version,$interp ,$type\n";
> #print "$last";
> push(@temparray, $last);
> }
>
> @temparray = sort @temparray;
> print "@temparray";
>
> Anthony asked, where the spaces came from, expecting the output of $last and
> @temparray to be the same.
>
> Of course, you are right about the interpolation used before the print : i
> just meant to point out that the newlines AND the spaces in his print
> "@temparray" are a result of the quotes used with print, and his attachment
> of \n to $last before the push @temparray,$last - without making it to
> complicated.
strings. The spaces after the newlines are added because that's how arrays
are interpolated in double-quote context, but they're nothing to do with the
original newline! Whatever the last character in each element is, the interpolation
"@temparray" puts a space between the elements, as I showed with my simpler example
with just single-letter strings.
Yes. Strictly "@temparray" is the same as> (Tim also hinted to $").
join $", @temparray
but $" is one of the built-in variables that I think it's best to forget about,
as if you want something other than the default you can just write a 'join'
with the separator you want and avoid obscure code.
Maybe. I'm not sure where you're misunderstanding what I wrote. Anyway, I hope this> Or did I totaly miss something.
helps.
Rob
Rob Dixon Guest
-
Wolf Blaum #8
Re: array push
For Quality purpouses, Rob Dixon 's mail on Tuesday 27 January 2004 12:42 may
have been monitored or recorded as:
...> Didn't you mean to put spaces before the last three records? This will be
> the result of
>
well - in Anthonys original mail there were spaces - i just copied that.
ok - I think we are talking about the same thing here.>> > Or did I totaly miss something.
> Maybe. I'm not sure where you're misunderstanding what I wrote. Anyway, I
> hope this helps.
thx, wolf
Wolf Blaum Guest
-
Rob Dixon #9
Re: array push
Wolf Blaum wrote:
Yes. These are the values of each string before they are pushed onto the array>
> For Quality purpouses, Rob Dixon 's mail on Tuesday 27 January 2004 00:30 may
> have been monitored or recorded as:
>>> > The right conclusion for the wrong reasons Wolf! The spaces are the result
> > of interpolating the array into a string, and the presence of a newline on
> > each array element is immaterial:
> >
> > my @arr = ('A', 'B', 'C', 'D');
> > print "@arr\n";
> > print @arr, "\n";
> >
> > **OUTPUT
> >
> > A B C D
> > ABCD
> well, maybe Im totally wrong here, but getting these results :
>
> $last printed out
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
(In the order they are pushed but before they're sorted).
Didn't you mean to put spaces before the last three records? This will be the> @temparray printed out
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
> TMR2,mpd_gw,50,w32-ix86,client
result of
print @temparray;
which is the same as
print $temparray[0], $temparray[1], $temparray[2], $temparray[3];
not
print "@temparray";
which is the same as
print join ' ', @temparray;
Thew newlines in the output are there because they were in the original> from this code:
>
> Code:
> if (something){
> $last = "$tmrname,$gateway_hash{$gateway},$version,$interp ,$type\n";
> #print "$last";
> push(@temparray, $last);
> }
>
> @temparray = sort @temparray;
> print "@temparray";
>
> Anthony asked, where the spaces came from, expecting the output of $last and
> @temparray to be the same.
>
> Of course, you are right about the interpolation used before the print : i
> just meant to point out that the newlines AND the spaces in his print
> "@temparray" are a result of the quotes used with print, and his attachment
> of \n to $last before the push @temparray,$last - without making it to
> complicated.
strings. The spaces after the newlines are added because that's how arrays
are interpolated in double-quote context, but they're nothing to do with the
original newline! Whatever the last character in each element is, the interpolation
"@temparray" puts a space between the elements, as I showed with my simpler example
with just single-letter strings.
Yes. Strictly "@temparray" is the same as> (Tim also hinted to $").
join $", @temparray
but $" is one of the built-in variables that I think it's best to forget about,
as if you want something other than the default you can just write a 'join'
with the separator you want and avoid obscure code.
Maybe. I'm not sure where you're misunderstanding what I wrote. Anyway, I hope this> Or did I totaly miss something.
helps.
Rob
Rob Dixon Guest
-
Rob Dixon #10
Re: array push
Wolf Blaum wrote:
But my point was that your post /didn't/ include the spaces :)>
> For Quality purpouses, Rob Dixon 's mail on Tuesday 27 January 2004 12:42 may
> have been monitored or recorded as:
>> ..> > Didn't you mean to put spaces before the last three records? This will be
> > the result of
> >
> well - in Anthonys original mail there were spaces - i just copied that.
I hope so, but I'm still a little worried that you think it's to do>> >> > > Or did I totaly miss something.
> > Maybe. I'm not sure where you're misunderstanding what I wrote. Anyway, I
> > hope this helps.
> ok - I think we are talking about the same thing here.
with having newline characters at the ends of the array elements. It
isn't!
Rob
Rob Dixon Guest



Reply With Quote

