Perl File Reading Line By Line (RegEx) -


what trying open file , read line line.
once found regex looking for, want place each 1 @accounts array print them onto screen.

though i'm not getting result. must making simple mistake here?

#!/usr/bin/perl  use strict; use warnings;  $line; $file; $start; $end; @match; @accounts;  print "enter file name (example: file.txt): "; chomp ($file = <stdin>);   open file, $file or die "cannot open $file read :$!";  while ($line=<file>) {      $start = '">';     $end = '</option>';      @match = ($line =~ /$start(.*?)$end/g);      foreach (@match)     {         push @accounts, $_;         print " $_\n ";     } } 

1) don't use bareword filehandles:

open $infile, '<', $fname     or die "couldn't open $fname: $!"; 

2) @match?? used g flag, @matches better name. generally, array names going plurals.

3) avoid using $_ in code:

for $match (@matches) {     print $match; } 

for , foreach same thing in perl, use for--it's shorter type.

4)

$start = '">';

are sure want double quote followed > ?? code works fine me data file:

<option">hello world</option> 

however, strange looking data.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -