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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading from files.

Status
Not open for further replies.

northernbloke

Programmer
Aug 9, 2000
29
GB
I am having problems with my data files.
They are created elsewhere and contain lines of text between 12 and 3000 characters. These Chars contain escape and special chars (line feed form feed etc).

ie:

e à ¯ï    z| “act_mdowe  e  MANDYDOWEPC e à ¯ï  “ з!}e à ¯ï  

That is one line. If the line is a small line without special chars - I can cope. I strip out the users name (act_mdowe) If it is a large line or has special chars the perl script exits before all lines in the input file have been processed.

@inp = <FILE>;

foreach $inr (@inp) {
&checkline();
}

sub checkline() {
while ($inr =~ /[a-zA-Z]{3}_[a-zA-Z]{1,}/g) {
print &quot;found $&\n&quot;;
@array[$num++] = &uppercase($&);
}

this works happily on pure text files - what am I missing if I want to deal with 'odd' data files.

Any pointers welcomed.
A bloke in need....
 
Is this on NT by any chance? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Yes its NT4

Perl 5.22

I am currently using an editor to manually strip out the junk - not ideal as the files are getting steadily bigger.

Thanks.
 
Code:
#!perl
open(INPUT,&quot;<nasty.input&quot;);
while (<INPUT>) { $buffer .= $_; }
close INPUT;
$buffer =~ s/[^\w]+/ /gis;
Code:
print &quot;$buffer\n&quot;;

That should pull all non-word characters from the file. If you are new to Tek-Tips, please use descriptive titles, check the FAQs,
and beware the evil typo.
 
I'm new to perl. How do I read from a separate inventory file that writes back to STDOUT. The inventory file is named inventory.
 
goBoating's answer should suffice for you(wondering) too, but I'll reiterate for you the &quot;open&quot;, &quot;while&quot; loop to read lines, and &quot;print&quot;:

my $abs_filename = &quot;/path/to/file&quot;;
open(INPUT,&quot;<$abs_filename&quot;) || die &quot;Can't open $abs_filename for input: $?&quot;
while (<INPUT>) {
print; ### prints to STDOUT by default
}
close(INPUT);

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top