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

I would like to test a group of phrase by using Perl scripting, for example: Kilo_Kili_asc.html Jiko_Huji_asc.html Puji_Huki_asc.html The perl script should be able to test 1)First word is capital. 2)Second word after "_"is also capital 3)third word after"-" is small capital and, 4)finally will be closed by ".html" and any phrases that don't meet that 4 criterias will be printed out in text document. I am a beginner in perl scripting,can anyone help me..plss

Replies are listed 'Best First'.
Re: Perl Scripting for testing
by Zaxo (Archbishop) on Mar 31, 2005 at 08:40 UTC

    This is a case for a perl regular expression. It should look something like this,

    my $re = qr/^[A-Z][^_]*_[A-Z][^_]*_[a-z][^.]*\.html$/; open my $fh, '>', 'badnames.txt' or die $!; while (<DATA>) { print $fh $_ unless m/$re/; } close $fh or die $!; __DATA__ Kilo_Kili_asc.html kilo_Kili_asc.html Jiko_Huji_asc.html Jiko_Huji_asc.htm Puji_huki_asc.html Puji_Huki_Asc.html
    qr is a quoting operator which lets you precompile a regex for later use.

    After Compline,
    Zaxo

      Since the OP states that he/she is a beginner with perl, some explanation of Zaxos regex might be useful.

      From the left:

      • /^[A-Z] - the / starts the expression, the ^ means 'at the beginning of the string', the square brackets mean 'any of these characters', and the A-Z means 'the range from A to Z'
      • [^_]* - match a number of characters that are not underscores. In this context the ^ character means NOT, rather than its other meaning as 'beginning of line'
      • \.html$/ - the \ escapes the dot, which would otherwise (in a regex) mean 'any character', html is obvious, then the regex closes with $, meaning 'end of string', and finally the / ends the expression.

      The rest of the regex is either plain characters, or variations on these, so thats probably sufficient.

      g0n, backpropagated monk
        In the mainstream of understanding REs, (s)he could also find useful YAPE::Regex::Explain, as suggested by davis in this post, which really revealed me a whole world!

        Flavio

        Don't fool yourself.
Re: Perl Scripting for testing
by fairul82 (Initiate) on Apr 01, 2005 at 01:43 UTC
    This is anothers thing.. all the links in html form are consolidated in .xml file. For example; <?xml version="1.0" encoding="UTF-16" ?> - <book name="NodeB_R1_5" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x.html"> <item name="Location" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Location.html" /> <item name="Implementation Desc" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Implementation_Desc.html" /> <item name="Responsible Person" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Responsible_Person.html" /> <item name="Phone Number" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Phone_Number.html" /> <item name="MAIL Account" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_MAIL_Account.html" /> <item name="Remarks" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Remarks.html" /> <item name="Text File" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Text_File.html" /> <item name="Name" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Name.html" /> <item name="Serving RNC" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Serving_RNC.html" /> <item name="Software Version" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Software_Version.html" /> <item name="Reset Status" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Reset_Status.html" /> <item name="Time of Last Reset Request" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Time_of_Last_Reset_Request.html" /> <item name="PM Collection Status" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_PM_Collection_Status.html" /> <item name="Time of Last PM Collection Request" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Time_of_Last_PM_Collection_Request.html" /> <item name="Sync Status" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Sync_Status.html" /> <item name="Sync Failure Reason" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Sync_Failure_Reason.html" /> <item name="Time of Last Sync Request" url="nodebattributes/NodeB_R1_5_NodeB_Rn_x_Time_of_Last_Sync_Request.html" /> <item name="Alarm Sync Status" ... So i need to test those nodebattributes(html link)that in xml file with that previous 4 criterias... anyone would like to help me?hmmm