in reply to perl extraction from a file

You can make use of regular expressions or modules like XML::Twig.

one way to do this is

undef $/; $str =<DATA>; while ($str =~ /<([^\/]*[^>]*)>((?:(?!<\/\1>).)*)<\/\1>/gsi) { print "Data inside $1 tag:\t$2\n"; }

This works only if the tag does not have attribute like your input.

Thanks in advance

Prasad

Replies are listed 'Best First'.
Re^2: perl extraction from a file
by Samy_rio (Vicar) on Nov 08, 2005 at 09:52 UTC

    Hi, Below code will work with or without attributes. Try this,

    undef $/; $str =<DATA>; while ($str =~ /<([^\/ ]+) ?[^>]*>((?:(?!<\/\1>).)*)<\/\1>/gsi) { print "Data inside $1 tag:\t$2\n"; } __DATA__ <user_name type="new">$userId</user_name> <job_id>$jobId</job_id> <finish_time>$timeF$ampmF</finish_time> <status cate="true">COMPLETED</status>

    Regards,
    Velusamy R.


    eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';