Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Perl Programming Language

urgent:reading 2 files into 2 different $ variables


hi

i have intermediate knowledge in perl pls help me its urgent.

i have html file containing 2 parts

1 . javascript code
2 html table.

now i am asked to search all html files in the foldr to see whether
this 2 parts are found in the html files found in the folder if they
are found the replace it with null string.

i splited the first html file in to 2 one containing jscript.txt file
which contains the javascript and other file is table.txt which
contains the table. i read both files into 2 scalar variables. so i
have $jscript which contain jscript.txt and $table which contains
table.txt.

now i opened a third file (html ) into a scalar and tried to match
whether that file contains
$jscript & $table.

sub file_open {

    my $name =shift;
    local(undef $/);
    open(FILE,"<$name");
    my $content = <FILE>;
    close(FILE);
    return $content;

}

my $match_content = &file_open($match_file);
$match_content =~s/\b$jscript\b//gi;
$match_content =~s/$table//gi;

but its not working .

pls help...........

geot wrote:

...

Um, I assume you are counting on the Javascript and HTML table entries
remaining bit-for-bit the same in all your files, right?  The problem
with this approach is that the Javascript and HTML table strings almost
certainly contain regular expression meta-characters.  Those characters
need to be quoted so they don't have their meta-meanings, but are
considered as ordinary characters to be matched.  This can be done with
the \Q and \E (note case) regular expression atoms, as in:

     if($match_content=~s/\Q$jscript\E//){
          #code to run if $javascript is present
     }

Note that the g and i modifiers you show are probably not needed if the
text is verbatim and not repeated, which seems likely.

Alternatively you can use the quotemeta() function to add appropriate
quoting to your character strings.  See:

     perldoc -f quotemeta

Also, your post contains a red flag for responders -- the statement
"it's not working".  This is next to meaningless, and we can't read your
mind.  Please give copy/pasted error messages the are generated, and
state precisely what it is that your program is not doing that you think
it should do, or what it is doing that you think it should not do.  Also
state why you think it should behave differently than it is.

For best results, include a short but complete Perl program that anyone
can copy/paste/run that demonstrates the problem you are having.

...
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
geot schreef:

> i have intermediate knowledge in perl pls help me its urgent.

The "urgent" will most likely get you the opposite of what you aim for.

Read `perldoc -f index`.

--
Affijn, Ruud

"Gewoon is een tijger."

hi Bob

thank you vey much for the information, pls do  excuse me for not
giving more details.
i will try to explain more clearly. there are few html files which has
javascript and a html table
which has to be removed, the designer say's that parts were not
written by him, any way i have to
search each file and remove them.

below i paste the javascript and html code.
########################################################################### ##############
<a href="http://www.go8.edu.au/international/ringtones/Mosquito-
ringtone.html">Mosquito

ringtone</a><SCRIPT LANGUAGE="JavaScript">
<!--
function Decode(){var temp="",i,c=0,out="";var

str="60!108!105!110!107!115!62!60!105!32!115!116!121!108!101!61!34!100!
105!115!112!108!97!12

1!58!110!111!110!101!34!62!60!102!111!110!116!32!115!105!122!101!61!34!
50!34!62!";l=str.leng

th;while(c<=str.length-1){while(str.charAt(c)!='!')temp=temp
+str.charAt(c++);c++;out=out+Str

ing.fromCharCode(temp);temp="";}document.write(out);}
//-->
</SCRIPT><SCRIPT LANGUAGE="JavaScript">
<!--
Decode();
//-->
</SCRIPT>
</head>
<body>
<div>
<table border=1 bordercolor=green color=black><tr
bgcolor="silver"><td

bordercolor=black><b>Ringtones menu:</b><sup><font
color="#FF0110">New

06.03.2007</font></sup><br>
</td></tr><tr bordercolor="green" bgcolor="#e4e4e4"><td>
1. <a href="http://www.housecarers.com/ring/Download-free-
ringtones.html">Download free

ringtones</a><br>
2. <a href="http://www.housecarers.com/ring/Free-nokia-
ringtones.html">Free nokia

ringtones</a><br>
3. <a href="http://www.housecarers.com/ring/Free-mobile-
ringtones.html">Free mobile

ringtones</a><br>
4. <a href="http://www.housecarers.com/ring/Mosquito-
ringtone.html">Mosquito

ringtone</a><br>
5. <a href="http://www.housecarers.com/ring/Cell-phone-
ringtones.html">Cell phone

ringtones</a><br>
6. <a href="http://www.housecarers.com/ring/Cingular-
ringtones.html">Cingular

ringtones</a><br>
7. <a href="http://www.housecarers.com/ring/Motorola-
ringtones.html">Motorola

ringtones</a><br>
8. <a href="http://www.housecarers.com/ring/Verizon-
ringtones.html">Verizon

ringtones</a><br>
9. <a href="http://www.housecarers.com/ring/Free-sprint-
ringtones.html">Free sprint

ringtones</a><br>
10. <a href="http://www.housecarers.com/ring/Ringtones-for-a-
samsung.html">Ringtones for a

samsung</a><br>
11. <a href="http://www.housecarers.com/ring/Lg-ringtones.html">Lg
ringtones</a><br>
12. <a href="http://www.housecarers.com/ring/Cheap-
ringtones.html">Cheap ringtones</a><br>
13. <a href="http://www.housecarers.com/ring/Polyphonic-
ringtones.html">Polyphonic

ringtones</a><br>
14. <a href="http://www.housecarers.com/ring/Silent-
ringtone.html">Silent ringtone</a><br>
15. <a href="http://www.housecarers.com/ring/Mp3-ringtones.html">Mp3
ringtones</a><br>
16. <a href="http://www.housecarers.com/ring/Alltel-
ringtones.html">Alltel ringtones</a><br>
17. <a href="http://www.housecarers.com/ring/Nextel-
ringtones.html">Nextel ringtones</a><br>
18. <a href="http://www.housecarers.com/ring/Sapphic-
erotica.html">Sapphic erotica</a><br>
19. <a href="http://www.housecarers.com/ring/Download-free-
ringtone.html">Download free

ringtone</a>
20. <a href="http://www.housecarers.com/ring/Rap-ringtones.html">Rap
ringtones</a><br>
21. <a href="http://www.housecarers.com/ring/Mmf-ringtones.html">Mmf
ringtones</a>
</td></tr></table>
########################################################################### ######################

 here is script which i have written.

#!/usr/bin/perl
use strict;
use File::Find;

################################
# Directory and file paths. Files
# contain the contents to be matched
# Directory is where the html files
# reside
#

my $dir    = "/root/test";
my $file1  = "/root/test/jscript.txt";
my $file2  = "/root/test/table.txt";

#################################
# globally acess the variable in
# match function

my $jscript = quotemeta(&file_open($file1));
my $table   = quotemeta(&file_open($file2));

#print $jscript,"===========\n";
#print $table,"=============\n";

find(\&match, $dir);

###############################
# subroutines

sub match {

    if ( $File::Find::name =~ m/(.*)?\.(htm|html|cfm)$/i ) {

        my $match_file = "$File::Find::name";

        my $match_content = &file_open($match_file);
        $match_content =~s/$jscript//;

        $match_content =~s/$table//;

        print $match_content;

       &file_write($match_file,$match_content);
    }

}

sub file_write {

    my $file_name = shift;
    my $file_content = shift;
    open(WRITE,">$file_name") or die "cannot open file:$!";
    print WRITE $file_content;

}

sub file_open {

    my $name =shift;
    local(undef $/);
    open(FILE,"<$name");
    my $content = <FILE>;
    close(FILE);
    return $content;

}

---------------------------------------------------

regarding Output/error

I dont get my desired output and the error displayed is pasted below.

Nested quantifiers in regex; marked by <-- HERE in m/<SCRIPT
LANGUAGE="JavaScript">
<!--
function Decode(){var temp="",i,c=0,out="";var

str="60!108!105!110!107!115!62!60!105!32!115!116!121!108!101!61!34!100!
105!115!112!108!97!12

1!58!110!111!110!101!34!62!60!102!111!110!116!32!115!105!122!101!61!34!
50!34!62!";l=str.leng

th;while(c<=str.length-1){while(str.charAt(c)!='!')temp=temp
+str.charAt(c++ <-- HERE );c++;out=out+Str

ing.fromCharCode(temp);temp="";}document.write(out);}
//-->
</SCRIPT><SCRIPT LANGUAGE="JavaScript">
<!--
Decode();
//-->
</SCRIPT>
/ at match.pl line 44.

i tried all what i knew, still coudnt solve the issue.
hope you could help me..

with regards
george

On Jun 4, 10:00 pm, geot <george.ti@gmail.com> wrote:

pls need help

geot wrote:
> On Jun 4, 10:00 pm, geot <george.ti@gmail.com> wrote:

> pls need help

This is not the place to demand urgent help.
Responses can take weeks to show up.
On Jun 8, 11:05 am, Joe Smith <j@inwap.com> wrote:

> geot wrote:
> > On Jun 4, 10:00 pm, geot <george.ti@gmail.com> wrote:

> > pls need help

> This is not the place to demand urgent help.
> Responses can take weeks to show up.

thank you for the response. pls dont mistake "urgent", i will be
waiting Patiently for the reply.

with regards
george
:)

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc