KevinADC 192 Practically a Posting Shark

I trust O'Reilly significantly more than wikipedia. I also read on MSDN (will post when I get home) that it's the API calls and programs that do the translation, not NTFS Native.

Its windows itself. Support for forward and backslashes in builtin to Windows. You can google around and find MicroSoft articles that explain it if interested. I think thats enough on the subject.

KevinADC 192 Practically a Posting Shark

Oh For The Sake Of Pete:

hehehe.... :)

KevinADC 192 Practically a Posting Shark

What have you tried?
Where are you stuck?

KevinADC 192 Practically a Posting Shark

He said he wanted the logic but what I suspect he really wants is code. I prefer to write code for people that show effort.

KevinADC 192 Practically a Posting Shark

Just to add a bit to the discussion. I was reading the perl FAQs to answer a question on a forumand came upon this:

Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work?

Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape character. The full list of these is in "Quote and Quote-like Operators" in perlop. Unsurprisingly, you don't have a file called "c:(tab)emp(formfeed)oo" or "c:(tab)emp(formfeed)oo.exe" on your legacy DOS filesystem.

Either single-quote your strings, or (preferably) use forward slashes. Since all DOS and Windows versions since something like MS-DOS 2.0 or so have treated / and \ the same in a path, you might as well use the one that doesn't clash with Perl--or the POSIX shell, ANSI C and C++, awk, Tcl, Java, or Python, just to mention a few. POSIX paths are more portable, too.

KevinADC 192 Practically a Posting Shark

I just need the logic of doing it .The real data is very close to the data which i gave.

Use a regular expression and a counter.

Comatose commented: Exactly +10
KevinADC 192 Practically a Posting Shark

Since this will be very dependent on the exact data in the file there is little sense in trying to help with data that is something similar to the real data.

KevinADC 192 Practically a Posting Shark

I really have zero experience here so all I can do is wish you good luck.

KevinADC 192 Practically a Posting Shark

That link does not want to post on this forum

http://en.wikipedia.org/wiki/Path_(computing)

KevinADC 192 Practically a Posting Shark

I see that link I posted was broke, try again:

http://en.wikipedia.org/wiki/Path_(computing)

KevinADC 192 Practically a Posting Shark

You can see here listed under directory paths for Windows:

http://en.wikipedia.org/wiki/Path_(computing)

In fact they list DOS as also accepting both \ / in directory paths. Maybe there is a way in DOS to change the path seperator. But when I try it it does not work in DOS, but it does in Windows.

KevinADC 192 Practically a Posting Shark

I'm pretty sure windows does not support paths with / as the separator. Try this: cd / or cd /windows and then try this cd \windows . What I'm guessing happens here, is Perl (and other languages that do this, such as python) are smart enough to know that even though we hacker-esque folks use / in a path, that we really mean \, and naturally adjusts it

Thats DOS (or other shell), not Windows. DOS uses forward slashes as switches, so you can't use them in directory paths. But Windows does fully support them. Its Windows itself that translates forward slashes into backslashes. Try using backslashes in Unix directry paths with perl or python and see what happens.

KevinADC 192 Practically a Posting Shark

I have no esperience in what you are doing, but my first thought is are you sure you didn't make some type of a mistake? When you see a variable as literal text instead of the interpolated value of a variable its almost always a quoting problem.

KevinADC 192 Practically a Posting Shark

Window fully supports forward slashes in directory paths. It always has. You can start using them from now on. :)

This is the three argument style of open:

open(INFH, '<', 'full/path/to/gettysburgh.txt') or die $!;

Its safer to use than the two argument style:

I'm pretty sure its convered in the open() functions documentation:

http://perldoc.perl.org/functions/open.html

KevinADC 192 Practically a Posting Shark

try using the full path to the file:

open(INFH, '<', 'full/path/to/gettysburgh.txt') or die $!;

KevinADC 192 Practically a Posting Shark
if($form_element{'email'} =~ m/^[a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-]+([.][a-zA-Z0-9_\-]+)+[a-zA-Z]{2,4}$/i){
        $values = 0;
        $mail = "Valid!";
} else {
        $mail = "InValid!";
}
sid78669 commented: Excellently answered!! +1
KevinADC 192 Practically a Posting Shark

try:

while(/^\\insert{?(.*?)(\.tex)?}?/){

you don't need to escpae the {} brackets with \

KevinADC 192 Practically a Posting Shark

You too Mike, take care. Nice to "meet" you. I'm on the left coast in Southern California.

KevinADC 192 Practically a Posting Shark

Cool. Actually I have plenty of time to read and post on forums. For me thats not a problem. I'm a semi-retired grandfather these days. In fact I have to go and pick up a grandson from school in about 30 minutes.

KevinADC 192 Practically a Posting Shark

Hi Mike,

I have used Mason but on a limited basis. I don't actually do much programming or web work these days. I keep from getting too rusty by answering questions on forums.

Most of the people that ask for help on forums are students or newbies.

You might want to check out www.perlmonks.com if you haven't already. The questions range from beginner to extremely advanced. I read that forum but I don't post on it as there are already a lot of very good perl people answering questions there and quite often the questions posted are too advanced for me to answer anyway. You might find it stimulating.

The perl forum on tek-tips.com used to be pretty busy but has tapered off, as well as perlguru.com. They get activity but not like they used to.

The Daniweb perl forum is erratic. The average is just a few questions a month, mostly newbies or beginners with pretty easy questions.

Regards,
Kevin

KevinADC 192 Practically a Posting Shark

Too bad the OP will never come back here to read the replies. They got their answer on a different forum back in December 2008 and have pretty much never returned here since then.

KevinADC 192 Practically a Posting Shark

Awesome, I hope to see you around.

KevinADC 192 Practically a Posting Shark

Well, we are in the same boat, I never learned perl formally either. Last time i was in school I was learning how to write programs on punch cards. Which totally turned me off to programming for a very long time. ;)

KevinADC 192 Practically a Posting Shark

Cool. Its sort of moot anyway in this example since tr/// is really the better way to do it since it involves no pattern matching, just simple character recognition.

I just thought the construct was interesting:

$count = () = /[a-z]/g;

I remember the first time I saw that years ago and it was a bit of a revelation in how perl works.

KevinADC 192 Practically a Posting Shark

mishel Offline
Newbie Poster
What does the community think of mishel?
Community Reputation Points: 10
Reputation-Altering Power: 0
How helpful is mishel at solving threads?
Solved Threads Replied To: 0
Last Activity: Oct 6th, 2008

I'm eager to help too, but posting code for a person that has not been here for months is probably something I wouldn't do. Its your decision though.

Welcome to DaniWeb, good to have another perl person around.

KevinADC 192 Practically a Posting Shark

An interesting construct to do the same thing. No need to actually use a named array:

$_ = "fooFOObarBAR";
$count=()=/[a-z]/g;
print "$count\n";

But I would do it like this myself:

$_ = "fooFOObarBAR";
$count = tr/a-z/a-z/;
print "$count\n";
KevinADC 192 Practically a Posting Shark

Seems that maybe headedtomexico is now madeittomexico

Comatose commented: LMAO! Too True. +10
KevinADC 192 Practically a Posting Shark

s/(\w+)\.world/$1.earth/g;

KevinADC 192 Practically a Posting Shark

so when the conditional of $item1=="7880" fires it will check "/[7880,5192,7879,0]/=="7880"

Its possible (I think). Using a hash sounds like the better approach. Very simple example:

%item1 = (
   7880 => [7880,7879,5192,0],
   7879 => [7879,7880,5192,0],
   5192 => [5192,7880,7879,0],
);

$item1 = $item1{$ARGV[0]} || die "Usage: no item found\n";

In the above if $ARGV[0] equaled 7880 then $item1 will be a reference to an array : [7880,7879,5192,0]. The first value is:

$item1->[0]

And so on for the other values in the array reference. The concept is pretty straight forward, but the implementation might not be.

KevinADC 192 Practically a Posting Shark

It could have something to do with a regexp, but since we can't see any regexps your code uses, there is no way to tell.

KevinADC 192 Practically a Posting Shark

There is no short or easy answer to your questions.

Perl uses the DBI (Database Interface) module to interact with a database. You also have to install the relevant drivers. For example if you wanted to communicate with a MySQL datasase you would install DBD::mysql.

For interaction with Excel you would use one of the Excel modules. The Excel module (or modules) would also need to be installed as they are not core perl modules.

The place to start on this long journey is CPAN:

http://search.cpan.org/

You can find the DBI module and DBD::mysql and search for Excel and read through the documentation of the Excel modules to find one that will suit your requirements.

My database skills are so rusty that I will not be able to help you there and I have never used any of the Excel modules so I can't help with that either. Google will be your friend to find resources.

KevinADC 192 Practically a Posting Shark

OK, good luck.

KevinADC 192 Practically a Posting Shark

just a guess, in this block of code:

#open (MLB2, ">> /data/local/GIS/WRKGIS.txt");
open (MLB2, ">> /awips/dev/localapps/kmltools/WRKGIS1.csv");
for ($i=1; $i<=$num1; ++$i){
 if ($finline[$i] =~/[A-Z]+/ ){
 write(MLB2);
format MLB2=
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$finline[$i];
.
 }
}

change $i<=$num1 to $i<$num1

KevinADC 192 Practically a Posting Shark

see the other forum, I prefer to not duplicate my replies.

KevinADC 192 Practically a Posting Shark

I see you posted the same question on another forum and provided more detail. My suggestion above will not do what you want.

KevinADC 192 Practically a Posting Shark

csv files typically use quotes around fields that have text or non-digit data in them. If you don't want the quotes you can try this:

print (join ',' , "@dn", # row
map {get $entry, $_->[1], $_->[2]} @fields)."\n";
}
KevinADC 192 Practically a Posting Shark

PPM is not for running your perl programs. Its for installing modules and other tasks related to modules. On Windows the way I prefer to run a perl program is open a DOS (or Command) Window and type:

perl scriptname optional-arguments

You may need to add the path to the perl program:

perl c:\whatever\scriptname optional-arguments

activeperl also comes with a whole lot of documentation so you need to start reading it.

KevinADC 192 Practically a Posting Shark

If you tried to run your code it will return a syntax error so I am suspicious you did not try it. In the other code the "while" loop has a condition:

while (1) {

why did you remove the condition in parenthesis?

KevinADC 192 Practically a Posting Shark

A students best cheat tool is a search engine or the search feature of a website or forum. You would have found a recent thread discussing the exact same assignment had you done just a little searching.

http://www.daniweb.com/forums/thread169597.html

Salem commented: I like it :) +27
KevinADC 192 Practically a Posting Shark

The Benchmark documentation says:

CAVEATS

Comparing eval'd strings with code references will give you inaccurate results: a code reference will show a slightly slower execution time than the equivalent eval'd string.

The real time timing is done using time(2) and the granularity is therefore only one second.

Short tests may produce negative figures because perl can appear to take longer to execute the empty loop than a short test; try:

timethis(100,'1');

The system time of the null loop might be slightly more than the system time of the loop with the actual code and therefore the difference might end up being < 0.

KevinADC 192 Practically a Posting Shark

You can try the Benchmark or Time::HiRes modules, they come with perl. Read the documentation and try a few things, if you get stuck post back.

KevinADC 192 Practically a Posting Shark

Here is a simple test of the regexp I posted:

$row = [qq{this is\n a test},qq{this is\ranother test}];
s/[\r\n]// for @{$row};
print @{$row};

That appears to work fine. Why it causes your code to seemingly hang, I don't know. In the code you posted before, do this:

my $row = $csv->getline ($fh);
print $row,"\n";

and see what $row is. If it does not return something like ARRAY(0x155526c) then what does it print?

KevinADC 192 Practically a Posting Shark

this line is doing nothing (its useless):

($ch);

I am not sure what you think this does:

open(OUT, "<$file") || die "Cant open $file: $!";
for($line=0; <OUT>; $line++)
{ 
}

I'm surprised that doesn't return a syntax error, but it definetly isn't doing anything and that is where $line is used only once. If you want to count the lines in the file:

open(OUT, "<$file") || die "Cant open $file: $!";
$line++ while (<OUT>);
KevinADC 192 Practically a Posting Shark

Post you code again, the code that returns the warning you mention. "Useless use of variable" is generally something like:

$foo;

The above line does nothing, its useless. Thats a warning though, not an error. And the other warning is obvious, you have something used only once in your program (a sclar or filename or filehandle, etc) , that is also a warning.

KevinADC 192 Practically a Posting Shark

Well, I don't know what the character is that is causing the problem but it appears you will need to remove it manually, something like:

my $row = $csv->getline ($fh);
s/[\r\n]// for @{$row};

KevinADC 192 Practically a Posting Shark

You can't run commands inside of strings, well you can but its easier to just do it properly:

open(MYFILE, ">>/usage.file");
print MYFILE 'USERID: ', `whoami`, 'used this on DATE: ', `date`, "\n";
close MYFILE

if whoami and date return with a newline then the above line will be broken up into two or three lines. You may want to do something like this instead:

my $who = `whoami`;
my $date = `date`;
chomp $whoami;
chomp $date;
open(MYFILE, ">>/usage.file") or die "$!";
print MYFILE "USERID: $whoami used this on DATE: $date\n";
close MYFILE

Of course the better solution is to use perl variables/functions for the date and whoami.

my $date = scalar localtime;
open(MYFILE, ">>/usage.file") or die "$!";
print MYFILE "USERID: $ENV{'USER'} used this on DATE: $date\n";
close MYFILE

I am assuming $ENV{'USER'} is the same information as whoami returns.

KevinADC 192 Practically a Posting Shark
KevinADC 192 Practically a Posting Shark

FIrst thing I would recommend fixing the shebang line:

#!"C:\Program Files\xampp\perl\bin\perl.exe"

The quotes should not be there:

#!C:/Program Files/xampp/perl/bin/perl.exe

Note: You can use forward slashes on Windows

The only other thing I see that looks suspicious is these lines:

my $result =
        SOAP::Lite
        -> service($google_wsdl)
        -> doGoogleSearch(@params);

Try like this:

my $result =  SOAP::Lite->service($google_wsdl)->doGoogleSearch(@params);
KevinADC 192 Practically a Posting Shark

Thanks KevinADC, I just have two questions.
1) What is the +1 for after the int(rand 10)? I tried to see what happened if I got rid of it, and nothing was different.
2) Why is 1 the condition for the while loop? I tried what I had before, while ($guess != $thinkingof) and that told me I had an uninitialized value on that line. Is the 1 simply to get rid of that?

Murtan answered the questions but I want to expand a bit. Why the +1? Your code generates a random number 0-9. If the number is 0 (zero) then the person guessing the number can enter any non-numeric value and it will match because perl silently converts non-numeric values into 0 (zero) when used in numeric context, for example:

if ('hi' == 0) {
    print "WTF? Why does this print? 'hi' does not equal zero!";
}

You could check that the user input is just a simple number using a regexp, but to avoid the problem entirely I add 1 (one) to the return value of rand(10) so now the range is 1-10. Now that the zero is eliminated there can be no false matching of a string to a number. If you continue with perl the concept of how perl treats strings and number differently depending on the operator you use will become very important.

while(1) is an old construct to create an endless loop. It simply means:

while(there is a …
KevinADC 192 Practically a Posting Shark

Your code is quite close to getting it right, here is a way to do this type of looping guessing game:

use strict;
use warnings;

my $thinkingof = int(rand 10)+1;
while (1) {
   print "Pick a number 1 to 10\n";
   my $guess = <STDIN>;
   chomp $guess;
   if ($guess > $thinkingof){
      print "You guessed too high\n";
      next;
   }
   elsif ($guess < $thinkingof){
      print "You guessed too low\n";
      next;
   }
   print "YOU GUESSED RIGHT!! It was $guess\n";
   last;
}