Current location: Hot Scripts Forums » Programming Languages » Perl » push at array


push at array

Reply
  #1 (permalink)  
Old 04-09-11, 05:10 AM
bibiqna_21 bibiqna_21 is offline
New Member
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation push at array

Hi Everyone,

Im trying to read in a file, split it using variables like this ( ($short,$long,$sd)= split (/\|/,$line); )

and i need to push all the $short into an array which then i will have to print.

How do we push a variable into an array?


My script:

#!/usr/bin/perl -w

open (HANDLE, '/usr/local/zedit/termcap') or die $!;
@array = ();
while ($line = <HANDLE>)
{

next if $line =~ /^#/;
next if $line =~ /^ /;
next if $line =~ /^\t/;
next if $line =~ /^$/;
next if $line =~ /^ /;
($short,$long,$sd)= split (/\|/,$line);
push (@array,$short[0]);

}
close HANDLE;
Reply With Quote
  #2 (permalink)  
Old 04-11-11, 01:21 PM
wickedxter wickedxter is offline
New Member
 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
push(@array,$short);

will push the contents of $short in to the array @array and will for every line in the file. remove the [0] from $short. Split wont make an array @short and put every thing matched in it. It will reset. Also use strict module so u dont get unexpected variables.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help reading multi-dimensional array l3rady JavaScript 3 06-11-10 04:10 AM
Remove value from array Nikas PHP 1 05-20-09 03:20 AM
Multi-Dimensional Array Help Nikas PHP 17 05-04-09 02:10 AM
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' Dr. Forensics PHP 3 07-15-06 03:54 PM
linking to iframe not working :( j0d JavaScript 5 01-19-04 08:14 PM


All times are GMT -5. The time now is 04:56 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.