greatshots has asked for the wisdom of the Perl Monks concerning the following question:

monks,

2030221045|PV_RPC_RPCSTAT|nc_routing_point|region|NORM|5|0|\ |REGION_I +D|\ |\ |\ |t| 2030221045|PV_RPC_RPCSTAT|nc_routing_point|node_type|NORM|6|0|\ |"TBD" +|\ |\ |\ |t| 2030221045|PV_SG3G_NE_Specific|nokia_sgsn_routing_and_unit_data_1_raw| +nc_id|NCID|1|1|\ |NC_ID|\ |\ |\ |t| 2030221045|PV_SG3G_NE_Specific|nokia_sgsn_routing_and_unit_data_1_raw| +sgsn_id|RETR|2|0|\ |SG3G_ID|\ |\ |\ |t| 2030221045|PV_SG3G_NE_Specific|nokia_sgsn_routing_and_unit_data_1_raw| +day|RETR|3|0|\ |@MIDNIGHT|\ |\ |\ |t| 2030221045|PV_SG3G_NE_Specific|nokia_sgsn_routing_and_unit_data_1_raw| +starttime|STRT|4|0|\ |utime(STARTDATE & STARTTIME,"%Y-%m-%d %R")|\ |\ + |\ |t| 2030221045|PV_SG3G_NE_Specific|nokia_sgsn_routing_and_unit_data_1_raw| +endtime|ENDT|5|0|\ |utime(STARTDATE & STARTTIME,"%Y-%m-%d %R") + (Int +erval * 60)|\ |\ |\ |t| 2030221045|PV_SG3G_NE_Specific|nokia_sgsn_routing_and_unit_data_1_raw| +sgsnsccpgttreq|NORM|6|1|new_counter("int8","accumulation")|SCCPNBG021 +|\ |\ |\ |t| 2030221045|PV_SG3G_NE_Specific|nokia_sgsn_routing_and_unit_data_1_raw| +sgsnsccpmsghand|NORM|7|1|new_counter("int8","accumulation")|SCCPNBG01 +9|\ |\ |\ |t|
If the line matches with the pattern utime(STARTDATE & STARTTIME,"%Y-%m-%d %R") then
utime(STARTDATE & STARTTIME,"%Y-%m-%d %R") shouuld be changed to utime(STARTDATE & " " & START_TIME,"%Y-%m-%d %R")
rest of the line which does not match this pattern should not be affected

Replies are listed 'Best First'.
Re: matching the line which has special characters in it
by graff (Chancellor) on Nov 06, 2006 at 04:48 UTC
    look at the part of the perlre man page that describes the use of \Q and \E flags within the regex:
    my $seek = '@#]$%(*&Y^%'; my $test = 'This is a test to look for @#]$%(*&Y^% in text data'; print "found it\n" if ( $test =~ /\Q$seek\E/ );

    Update: I realized I answered only part of your question. It looks like you can minimize the regex and substitution to just this:

    s/(STARTDATE &) (STARTTIME)/$1 " " & $2/;
    But if that pattern occurs next to things other than "utime(", and you need to restrict the pattern more carefully, then you need to handle the parens -- a couple ways come to mind:
    # don't try to match the paren explicitly -- use "." instead: s/(utime.STARTDATE &) (STARTTIME)/$1 " " & $2/; # or match it explicity, with an escape: s/(utime\(STARTDATE &) (STARTTIME)/$1 " " & $2/;
    In any case, don't bother making the regex match string any longer than it needs to be.
Re: matching the line which has special characters in it
by Errto (Vicar) on Nov 06, 2006 at 04:52 UTC
    If you're using regular expressions, you should not run into any trouble with "special characters" as & , which I'm guessing is the character you're concerned about, is not a regex metacharacter. See perlretut and specifically the section on metacharacters and how to match them in a pattern.
      He would also need to worry about the parens, which, if not escape or disabled, would become a capture, rather than matching literal parens.
A reply falls below the community's threshold of quality. You may see it by logging in.