Hi.

I have a script which parses line by line from a file. In order to make the changes "online" , I use the "Tie::File" module, so I have an array abstraction for the file, as each line in the file goes to each entry in the array.

The problem is, The regex patterns which worked before using Tie, fails to work afterwards. I've printed the array to see that each entry has gone chomp on it. 1. Does it affect the regex? (chomp operation?) 2. If not, why my regex doesn't work? code is displayed..

my $filename = "prefs_defaults.cfg"; tie my @array, 'Tie::File', $filename or die "Could not open file '$fi +lename'. $!"; # open (my $fh, "+<", $filename) or die "Could not open file '$filenam +e'. $!"; #while(my $current_line = <$fh>) for (my $i = 0; $i <= $#array; $i++){ my $current_line = $array[$i]; # this is the abstract array. #print "$array[$i]\n"; #print "$current_line\n"; foreach my $field (keys %user_options) { if (($current_line =~ $field) and ( defined ($user_options{$fi +eld}))) { #print "Line which modified: $current_line\n" ; #print "user options: $user_options{$field}\n"; print "hello"; $current_line = $current_line."\n"; print $current_line; if ($current_line =~ /(.*?)=(\w+)(\s+.*)/) { print "left: $1\n"; print "middle: $2\n"; print "right: $3\n"; } $current_line =~ s/(.*?)=(\w+)(\s+.*)/$1=$user_options{$fi +eld}$3/; #print "$current_line\n"; $array[$i] =$current_line; #print "$array[$i]\n"; } }
} Some lines from the file I am trying to read:.
[RECORD_OBJECT] START_GUARD_TIME=666 END_GUARD_TIME=0 AUTO_START_GUARD_TIME=2 # =PREFS_API_RECORD_AUTO_START_GUAR +D_TIME_ON AUTO_END_GUARD_TIME=2 # =PREFS_API_RECORD_AUTO_END_GUARD_ +TIME_ON DELETION_MODES=1 # =PREFS_API_RECORD_DELETION_MODES_ +AUTOMATIC REVIEW=1800 REMINDER_TIME=0 CONFLICT_TIME=0 WARN_PERCENT=90 [UI_OBJECT] TIME_OUT=5 TRIGGER_TIME_OUT=1 # =PREFS_API_UI_TRIGGER_TIME_OUT_OF +F MESSAGE_ALERT=1 # =PREFS_API_UI_MESSAGE_ALERT_OFF BACK_MUSIC=1 # =PREFS_API_UI_BACK_MUSIC_OFF BEEP=1 # =PREFS_API_UI_BEEP_OFF SUBTITLE=1 # =PREFS_API_UI_SUBTITLE_OFF NARRATIVE=1 # =PREFS_API_UI_NARRATIVE_OFF HIGHLIGHTED_PROG=1 # =PREFS_API_UI_HIGHLIGHTED_PROG_OF +F BEEP_IF_NARRATIVE=1 # =PREFS_API_UI_BEEP_IF_NARRATIVE_O +FF REMOVE_ADULT_CHAN=1 # =PREFS_API_UI_REMOVE_ADULT_CHAN_O +FF FRONT_PANEL=2 # =PREFS_API_UI_FRONT_PANEL_STANDAR +D KEY_REPEAT=1 # =PREFS_API_UI_KEY_REPEAT_OFF KEY_REPEAT_INITIAL_DELAY=0 KEY_REPEAT_DELAY=0 MINI_TV=2 # =PREFS_API_UI_MINI_TV_ON [ANYTIME_OBJECT] OPT_IN=1 BROADBAND=1 QUEUE=2 NOTIFY=2 CONTENT_GROUP=0x00000002 # bitmask: 0x1 - SD, 0x2 - HD

In reply to Reuglar Expression with chomp and Tie by pejoya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.