Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

split issue 1

Status
Not open for further replies.

l3p15

Vendor
May 7, 2005
11
TH
Hi Experts,


I am trying learning perl, and found this issue,

datares :

ExternalNetwork=1,Cell=1234 att 555
ExternalNetwork=1,Cell=5678 att 553

script :
#!/usr/bin/perl
open (FILE, 'checkres');
while (<FILE>) {
chomp;
($name, $fr, $value) = split("\t");
print "Name: $name\n";
print "Attr: $fr\n";
print "Value: $value\n";
print "---------\n";
}
close (FILE);
exit;

but result not as I imagine :

Name: ExternalNetwork=1,Cell=21252 att 555
Attr:
Value:
---------
Name: ExternalNetwork=1,Cell=21472 att 553
Attr:
Value:
---------

Is there something that i missed ? ,
Thx for kind advice.

Greating from beginner'user

Lepi

additional : how about if I want to split again "ExternalNetwork=1,Cell"
 
try
Code:
($name, $fr, $value) = split();
or
Code:
($name, $fr, $value) = split(/\s+/);

If you want to split "ExternalNetwork=1,Cell" with comma then try
Code:
#!/usr/bin/perl
open (FILE, 'checkres');
while (<FILE>) {
  chomp;
  ($name, $cell, $fr, $value) = split(/\s+|,/);
  print "Name: $name\n";
  print "Cell: $cell\n";
  print "Attr: $fr\n";
  print "Value: $value\n";
  print "---------\n";
}
close (FILE);
you will get
Code:
Name: ExternalNetwork=1
Cell: Cell=1234
Attr: att
Value: 555
---------
Name: ExternalNetwork=1
Cell: Cell=5678
Attr: att
Value: 553
---------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top