Computing.Net > Forums > Programming > Perl

Perl

Reply to Message Icon

Original Message
Name: aby
Date: August 29, 2002 at 16:06:06 Pacific
Subject: Perl
Comment:

Hi there,
I'm trying to play with a weird file with no specified delimiters on each line. The file "a.txt has following entries

users on abcd
username email passwd phone
aby aby loi 123
mag mag kiu 456
bet bet lop 789

users on degg

Now my problem is to process each line. I know its quite easy to do in Script (ksh).. a simple "read" command would accomplish that
But, can anyone help me accomplish this in perl ? I want to store each line's each word in an array "var"
So, for each line of my file, I want $var[0], $var[1] etc.
Thanks,
aby


Report Offensive Message For Removal

Response Number 1
Name: Tom
Date: August 30, 2002 at 04:11:32 Pacific
Subject: Perl
Reply: (edit)

@var = [FILEHANDLE];
Using the corner brackets instead of [ and ], which I can't post. Then you can split like this:
@array = split(/\s/, $var[0]);


Report Offensive Follow Up For Removal

Response Number 2
Name: junky_toof
Date: September 2, 2002 at 14:23:05 Pacific
Subject: Perl
Reply: (edit)

Proof positive why all perl users should learn awk before trying perl.
Yuk.


Report Offensive Follow Up For Removal

Response Number 3
Name: Muzammil Ali
Date: September 5, 2002 at 07:30:49 Pacific
Subject: Perl
Reply: (edit)

_____________________________________________
Hey
Anyone please fix this messenger for me
i m unable to fix it:
:::::::::::Below is the source Code::::::::::::::::::::::::::::
After Fixing It Please Email me At: alipf@myecom.net

#!/usr/local/bin/perl
$data_dir = "/cgi-bin";
my $database = "$data_dir/userpass.dat";
my $messages = "$data_dir/messages/";
my $thisURL = "http://searchall1.netfirms.com/cgi-bin/messenger.pl";
my $joinURL = "http://searchall1.netfirms.com/cgi-bin/messenger.pl?action=join";

use strict 'vars';
use CGI qw(:standard);

my ($action, $subaction, $step, $user, $pass, $userID, @lines, $logged, $error, $to, $message);
my ($data, $line, $check);

&gatherVars();
&performAction;

### PERFORM ACTION ###
sub performAction{
my %possibleAction = ( "join", 1,
"manage", 1);

if($possibleAction{$action}){
&printCommonHeader();
if ($action eq "join") {
&actionAdd();
}
if ($action eq "manage") {
&actionManage();
}
&printCommonFooter();
}
else{
## there is no action, then the main page is displayed
&printCommonHeader();
&actionHome();
&printCommonFooter();
}
}

sub actionHome{
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "Name : \n";
print "     \n";
print "\n";
print "\n";
print "\n";
print "Password : \n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\t\t\t\t\t\t\n";
print "\t\t\t\t\t\n";
print "\t\t\t\t\n";
print "\t\t\t\n";
print "\t\t\n";
print "\t\n";
print "\n";
print "\n";
print "\tfunction open(){\n";
print "\t}\n";
print "\n";
print "\n";
}

sub error {
my $msg = shift(@_);
++$error;
if ($error == 1) {
print "ERROR:\n";
print "\n";
print "\n";
print "UserName:\n";
print "PassWord:\n";
print "\n";
print "JOIN\n";
print "\n";
}
print "$msg\n";
}

### GATHER VARS ###
sub gatherVars {

$action = param('action') if(!($action = url_param('action')));
$subaction = param('subaction') if(!($subaction = url_param('subaction')));
$step = param('step') if(!($step = url_param('step')));
$user = param('user') if(!($user = url_param('user')));
$pass = param('pass') if(!($pass = url_param('pass')));
$userID = param('userID') if(!($userID = url_param('userID')));

$to = param('to') if(!($to = url_param('to')));
$message = param('message') if(!($message = url_param('message')));

$step = 1 unless $step;
}


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Perl 

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software