inked,
add this line to your code:
use warnings;
and rerun it and list any warnings you get.
inked,
add this line to your code:
use warnings;
and rerun it and list any warnings you get.
I am not interested in helping you.
Did you have a question? What perl code have you tried to write to solve your programming rquirements?
A google search found this page:
http://en.literateprograms.org/Category:Programming_language:Perl
It shows a "word count" program listed but I have not read it to see how well written it is.
And this one:
The concept of sentences does not translate well to poetry or song liricks as they do not follow the same grammatical rules as formal writing.
OK, when I run your code the count is 2. The problem appears to be that you are not chomping the input and you have "!" instead of "," in your conditional statement.
When "!" is changed to "," the count goes to 7 because the first sentence has 2 commas:
For the eyeing of my scars, there is a charge,
You also need to chomp $ch:
chomp($ch)
before comparing the strings.:
while(my $ch = getc(DATA))
{
chomp($ch);
if($ch eq "?" || $ch eq "," || $ch eq ".")
{
$sentences++;
}
}
You are comparing strings:
if($ch eq"?" || $ch eq "!" || $ch eq ".")
instead of searching for patterns:
if($ch =~ /[?!.]/)
EDIT: actually, let me try something, I think getc() might be affecting the code too. I never use it so I have to check how it works.
$str="http://server.com?name=foo&age=20&id=3&pass=123456"; $str=~s/^.*?\?//; while($str=~m/(.*?)\b=(.*?)(&|$)/){ print "$1----$2\n"; $str=$'; }
how will that parse the query string? That parses a string. There is no need to do something like that anyway nor is it advisable, use the CGI module or a CGI sub class to parse query or form data.
You're welcome.
Your latest code no longer has the end of string anchor ($) so it could match strings of any length as long as the initial pattern matches. But lets assume your code does have the end of string anchor and run a test:
while (my $file = <DATA>) {
chomp($file);
if( $file !~ m/^[a-zA-Z\_]{1}[a-zA-Z0-9\_]{7}(\.txt|\.TXT)$/){
print "$file - Incorrect format!\n";
}
else {
print "$file - correct format!\n";
}
}
__DATA__
qwertyuio.txt
12wedcfr.TXT
asd38_gy.TxT
asd38_gy.txt
@qwedcvnt.txt
asdfgter.txt
dgh!cbgt.txt
1234rtyuio.TXT
a123dfghj.txt
aqwertyu.gif
output:
qwertyuio.txt - Incorrect format!
12wedcfr.TXT - Incorrect format!
asd38_gy.TxT - Incorrect format!
asd38_gy.txt - correct format!
@qwedcvnt.txt - Incorrect format!
asdfgter.txt - correct format!
dgh!cbgt.txt - Incorrect format!
1234rtyuio.TXT - Incorrect format!
a123dfghj.txt - Incorrect format!
aqwertyu.gif - Incorrect format!
looks good to me.
Your second charcter class does not include an underscore, but say it does:
m/^[a-zA-Z_]{1}[a-zA-Z0-9_]{7}(\.txt|\.TXT)$/
since you are using string anchors ^ and $ it will match 8 characters and then the file extension. If your regexp is matching filenames with more than 8 characters followed by the extension you are doing something wrong. But since you did not post samples of the data (like I asked) its hard to say. Instead of [a-zA-Z0-9_] you can use \w which is the exact same thing:
m/^[a-zA-Z_]{1}\w{7}(\.txt|\.TXT)$/
when I run that against some test names it works as expected.
Post all of your code and some sample data.
your question is very hard to not only understand but also to read because you seem to not know how to make sentences that other people can read and make sense of so please edit your post and use proper grammar and post an example of the strings you are trying to match and the ones that think should match and ones you think should not match
how do I retreive query string in perl ?
let's say I have http://server.com?name=foo
how do I get the value of 'name'thx
Already answered on one or two other forums.
From an MS-DOS prompt it does the same thing, just if it is run in the DOS window, then when the program exits, the DOS program remains so the window remains open
Exactly, which is why I recommend running perl programs in a DOS window.
Comatose,
Sorry if my comments appeared to be directed at you. I should have quoted the OP to make sure he knew I was directing them at him.
Regards,
Kevin
Not only do you appear to never have heard of CPAN, maybe you never heard google or other search engine? The first result returned from google points to the CPAN archive as well as a wealth of other online resources related to the module:
http://www.google.com/search?&q=Parse::RecDescent
Learn to use search engines for these types of question instead of posting on multiple forums.
<SmartDrv<=<C:\\WINDOWS\\system32\\Setup\\SmartDrv.exe<
Almost all modules have documentation. And almost all modules are listed on CPAN:
http://search.cpan.org/~timb/DBI-1.607/DBI.pm
There are also many online resources that you can use a search engine to find and many perl books you can purchase or possibly borrow from a library if there is a library/school in your area.
It looks like it should work but it will not alter the original file if thats what you are thinking. The only reason it will not work is if the regular expression is not finding the search pattern: \b$pattern\b
When posting a question, saying "it does not work" is next to useless. You have to describe what happens when you run the code and post any error messages your code might return.
To search and replace in the same file here is a snippet you can look over:
As a beginner you should read the documentation for functions and modules and such things as you try and use them. You would notice that system() does not return any application output back to your perl script.
If you don't know how to read the perl documentation locally, you can read it online:
the version you have installed locally may not be the latest version of perl, which the online documentation is. But most of the core functions are still the same.
Next time I would prefer to see some effort to solve your programming reqirements before posting code. Here is one way it can be done:
my $dir = qx{dir};
open (my $OUT, ">", 'dir.txt') or die "$!";
print $OUT $dir;
close $OUT;
SO did u actually do something :? please share i also need it )
Considering the thread is more than 3 years old your chances of a reply are slim.
Cool, I suspected as such but was not sure. "foreach" is a list command and expects a list, so I was afraid it might be slurping in the entire file instead of reading the file line by line as a "while" loop does.
Your question, as has been well answered, makes no sense. Any code you distribute will not be secure.
The code will be of no interest to anyone that is not a code cracker but just wants to use the program. And no amount of encoding or obfuscating your code will be enough to hide it from anyone that wants to crack it. There is virtually nothing in between those two ends of the spectrum. You will be protecting your code only from the first group of people that have no interest in the code in the first place.
foreach is the wrong command to loop through a file but I am not sure if it is in anyway contributing to the problem. But try this:
while (<INPUTFILE>) {
See if it helps.
Well, I doubt there is a way to do it that is completely cross platform independent. Each perl version and even the same version for different operating systems and even the same version of perl for the same operating system but a different version of the operating all have quirks. Your chances of success are low.
I believe the filename should be on the same line as the call to your perl script:
perl -w test.pl test.txt
You did not use the code I posted. Just use the code I posted, only the code I posted and see what is printed. If this line does not work with the quotes:
print "<$_>" for @ARGV;
than your install of perl is no good. Please start using the code tags to post your perl code.
for right now test your program input:
use strict;
print "<$_>" for @ARGV;
see what gets printed. Use the code tags to post your perl code.
generic example:
open(my $FH, ">", 'path/to/file.txt') or die "$!";
print $FH "your data\n";
close $FH;
Thats not really enough information but try making the match non-greedy by adding '?':
(\w:\\.*?\.\w{3})
If its a mapped drive it may fail. I'm Not sure how you get perl to recognize a mapped drive. Maybe masijade will know.
try this, note the single-quotes:
chdir('c:\mnt') or die "Can't chdir to c:\\mnt : $!";
see if die returns an error.
Its actually better to use forward slashes even with windows, which fully supports their use in directory paths.
chdir('c:/mnt') or die "Can't chdir to c:/mnt : $!";
That way you avoid using perls escape operator \ in the wrong context in your perl code, like you did here:
chdir("c:\mnt");
which interpolates as:
chdir(c:nt);
or if the sequence \m is a valid meta character sequence perl would expand that into whatever it is (if anything). Like \t is a tab inside a double-quoted string.
Save the html page or the data only?
That is far from a beginners perl project. Makes no sense you would get a project like that and apparently have no idea how to even start.
Step one: Read the CGI modules documentation.
Open a DOS window (MS DOS Prompt)..... then try my suggestions.
A better alternative is to use an IDE. Perl Express is a free one for Windows. www.perl-express.com
Then you can write/edit/run programs in the IDE. Makes it easy to write programs and test them. I believe perl-express also has CGI and interactive I/O input options so you can feed data to the script like you would with a CGI script or command line program.
You must still have perl installed to use the IDE.
There is no such thing as a perl cookie. On the server end they are generally refered to as sessions, on the client side, they are called cookies. But there is no such thing as a perl cookie so I am not sure what you are wanting to do.
Are you familiar with the CGI module? You can set and read cookies with the module. See the CGI documentation for details.
http://perldoc.perl.org/CGI.html#HTTP-COOKIES
There is also the CGI::Cookie module
see devshed for a reply to your question
If you googled and couldn't find anything then I don't know what else to suggest.
There is no way to know why the download was slow, that has nothing to do with PPM. Either the downlaod site was busy or your DSL providor was busy or your computer might have been overloaded doing other things.
PPM does have its negative side but also a positive side. The PPM GUI makes things pretty easy in my opinion. The need to add repositories is a bit of a pain, it would be nice if all the modules that have been compiled to use with activeperl were stored in a central repository similar to CPAN. There is also less modules available if you use activeperl but that has nothing to do with PPM itself.
But running the PPM GUI is so simple. Just click on it. It opens, downloads the packlists, synchronizes the data, and then you can see all the modules that are already installed, the ones you can install, you can also uninstall, and more, all in an easy to use GUI interface. Like any software it takes a few tries to learn how to use it, or you could read the instructions.
There is strawberryperl which is a Windows port of perl that uses CPAN just like you would with Unix or Linux. Just don't try and install more than one version of perl on your windows box. It is near impossible to get to work (and might be impossible) given the nature of how Windows works. If you wanted to try …
Do you understand what the error means?
"Can't call method "SaveAs" on an undefined value at Y:/In/FileReport.pl line 183."
You have created an object in the perl script at some point that did not return a true value, something like:
my $object = FOO->new;
then you are trying to use a method of $object:
my $something = $object->SaveAs();
but because $object was never initialized you can't call any of its methods. You need to find out why the object is not being created properly.
There is no limit on the number of characters perl can store in a string. Maybe you meant something else.
There is also no numerical data type in perl. There are only scalars and lists of scalars. Scalars can be numbers or strings.
There are also a number of Math modules that come with perl that might be helpful:
Okey, I understand, the thing is I know just very little c++ and no perl, but somebody advised me that it will be easier for me to start with perl with no knowledge than in c++ with little knowledge, so that is why I asked.
I think that is true for most people. Perl should be easier to learn even if you already know just a little C++. I suggest you purchase a copy of "Perl BookShelf Reference" on CD. If you're a fast learner give yourself a couple of weeks to a month to grasp the basics:
data types
operators
perls built-in functions
from there you can jump around to accomplish what you need to do.
actually there was an error in this line:
(my $key,$value) = split(/=/,$string);
should have been:
my($key,$value) = split(/=/,$string);
THere is no one size fits all answer. Depends on your overall requirements not just the part you posted. Can perl do what you asked about? I am sure it can. Would it be easy? Not if you don't know any perl.