415 Posted Topics
Re: [QUOTE=shadiadiph;1261130]Sorry for another regex post but i have been trying to get a regex to work to check for unwanted characters in a string like @#?! I have tried [code] var cityreg=/^[^$%@!]+$/; [/code] but it doesn't seem to work?[/QUOTE]You need to assign the regex pattern object to a variable and … | |
Re: [CODE]>>> line_of_numbers = "5 7 6 35 346 245" >>> list_of_numbers = line_of_numbers.split() >>> print list_of_numbers ['5', '7', '6', '35', '346', '245'] >>> [/CODE] | |
Re: I haven't tested this but something like the following should work. It opens a new file for output using a prefix plus the input file name for the name of each output file.[CODE]#!/usr/bin/perl use strict; use warnings; #If you want to open a new output file for every input file … | |
Re: For really simple html you can use regular expressions. For more complex data it would be better to search CPAN for a good html parser module and learn how to use it (which I haven't got around to doing yet). Meanwhile the following script should do what you want.[CODE]#!/usr/bin/perl #ParseList.pl … | |
Re: [CODE]#!/usr/bin/perl use strict; use warnings; my %group; my $groupname; #Change the following line to assign path to your data file my $path = '/home/david/Programming/Perl/data'; my $filename = "$path/test.txt"; open(my $fh, '<', $filename); while (<$fh>){ chomp; if (m/^PREVIT/){ $groupname = $_; $group{$groupname} = 0; next; }else{ $group{$groupname}++; } } close $fh; … | |
Re: Worked fine for me in the MySQL monitor in terminal.[CODE]mysql> CREATE TABLE employees ( -> employeeNumber int(11) NOT NULL, -> lastName varchar(50) NOT NULL, -> firstName varchar(50) NOT NULL, -> extension varchar(10) NOT NULL, -> email varchar(100) NOT NULL, -> officeCode varchar(10) NOT NULL, -> reportsTo int(11) default NULL, -> … | |
Re: [QUOTE=En-Motion;1251364]Tried parenthesis but still same deal - only shows records with an entry in 'install' table, not all records. I think a JOIN might be what i'm after, but I'm not sure yet how to do it across 3 tables.[/QUOTE]It looks like you need a left join, but it's not … | |
Re: You could create a subroutine to which you pass each directory name and put your code in there. Try running the following first. It has a subroutine called 'something' that prints a message each time it is called. You could put your code in there.[CODE]#!/usr/bin/perl #DoSomethingInDirAndSubdirs.pl use strict; use warnings; … | |
Re: [URL="http://kodos.sourceforge.net/"]Kodos The Python Regex Debugger[/URL] suggests the following ways to find Plan Allowance value.[CODE]#!/usr/bin/env python import re rawstr = r"""Plan Allowance \(MB\)</td><td style="border-width:0px;">\s*(?P<Plan_Allowance>\d+)\D""" embedded_rawstr = r"""Plan Allowance \(MB\)</td><td style="border-width:0px;">\s*(?P<Plan_Allowance>\d+)\D""" matchstr = """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head> <meta http-equiv="refresh" Content="60;url=/stlui/user/allowance_request.html"> <title>Download Allowance Status</title></head><body><h3 style="font-size: 150%; color:blue; text-align:center; font-weight:bold">DOWNLOAD … | |
Re: What was the error that you saw in the terminal? If an error [I]other than[/I] IOError, UnicodeDecodeError or SyntaxError occurs (if that is possible?) then I think (haven't tested it) control would go to your else block which reports success. | |
Re: I'm not sure why you need an infinite loop but maybe you want to wrap the sendIP() in a try block. The finally block will quit the server whether or not your sendIP() succeeds or causes an exception.[CODE]#!/usr/bin/env python # This is the loop i need to break. I know … | |
Re: From what I've read, it's considered a best practice. One plus is that more than one web page can include the same script. Also if the script is called from different web pages and it's already in memory it doesn't have to be reloaded. I've been reading about it in … | |
Re: What are the names of your input files? Before you run your program you have 10 files. After you run it you will have 20 (10 input plus the 10 new output files). If you run your program more than once, the program will need to specify the names of … | |
Re: When you compare alphanumeric values with the numeric comparison operator you get true when you don't expect it. Change [CODE]while ($exp =="y") {[/CODE] to [CODE]while ($exp eq "y") {[/CODE][QUOTE]Binary "==" returns true if the left argument is numerically equal to the right argument. Binary "eq" returns true if the left … | |
Re: [code=text]>>> import webbrowser >>> webbrowser.open('/home/david/index.html') True >>> [/code]It opens my default browser, Firefox, and displays my index.html file. I think it's supposed to do the same on other platforms. | |
Re: My wife says I have to turn off the computer now so this is just a stub. The following shows you can use glob to do something to every file that is named according to a specific pattern:[CODE]#!/usr/bin/perl use strict; use warnings; my @files_to_integrate = glob("/home/david/Programming/Perl/xyz_channel_*.dat"); foreach my $f (@files_to_integrate){ … | |
Re: Please wrap your program in [noparse][CODE]Your program goes here[/CODE][/noparse] tags. Otherwise we can't see how the lines in your program are indented and have to guess. Also when you say it didn't work, do you mean that you got no output, or that the output was not what you wanted? … | |
Re: [QUOTE=maheshrmishra;1237387]is it possible to open and work in two files from same or different location simultaneously. How it is possible? Please suggest Thanks / Regards Mahesh[/QUOTE] Yes it is possible. How? When you open a file you assign it to a file handle which you give any name you want. … | |
Re: I made up the following data to test and put it in a file called 'users.csv'.[code=text]"Name","ComplicatedColumn","AccountDisabled","OnSite", "Fred","Age=25,Pet=Fish","0","1", "Donna","Age=29,Pet=Cat","0","1", "Tom","Age=35,Pet=Gerbil","1","0", "Linda","Age=27,Pet=Dog","0","0",[/code]The following works for me (finally) except if the "AccountDisabled" header name doesn't exist in the file it won't catch that error... so it may need better error-checking.[code]#!/usr/bin/perl use strict; use … | |
Re: I made up a simplified data file containing the following:[CODE=text]Tom,no,2009 Dick,no,2008 Harry,se,2010 Jane,ip,2009 Frank,te,2007[/CODE]Notice the last record has a deliberately invalid item for testing. The following should print your data, after looking up the desired values for $dat_type that are defined in a hash. Using a hash means you don't … | |
Re: [QUOTE=bjoernh;1232489]Hi there. Day 2 of programming python. In this thread I posted my first attempt [url]http://www.daniweb.com/forums/post1231604.html#post1231604[/url] and growing from there it goes to slightly deeper water here. I have three .txt files: nvutf8.txt here new vocab items are stored esutf8.txt here example sentences are stored exoututf8.txt example sentences from esutf8.txt … | |
Re: [QUOTE=jaydot;1218616]hi just wanna ask is it possible for perl to get the value of a print command? for ex. my $result = print "hello world\n"; print "$result\n"; why is it that the "print $result" would print a value which is 1?.. is it possible to get the result "hello world" … | |
Re: Look at vegaseat's code snippet about [URL="http://www.daniweb.com/code/snippet216475.html"]date and time handling[/URL] and scroll down to the part that says "Calculate difference between two times (12 hour format) of a day:". That looks like what you need. | |
Re: I haven't figured this out yet but I think the first step for something with somewhat complex CSV parsing requirements would be to choose and install a good CSV parsing module for Perl. There are some simple examples of [URL="http://perlmeme.org/tutorials/parsing_csv.html"]Parsing CSV at this link[/URL]. | |
Re: In your loop that builds your string, replace the following statement: [ICODE] $string .= $_;[/ICODE] with these: [ICODE] chomp; #Removes trailing new-line character from $_ $string .= "$_ "; # "$_ followed by one space"[/ICODE] [URL="http://perldoc.perl.org/functions/chomp.html"]http://perldoc.perl.org/functions/chomp.html[/URL] [QUOTE=rudasi;1225091]Hi, I have a file.txt, I need to enter the data in string. Currently … | |
Re: You can read the correct version of this code at [URL="http://diveintopython.org/power_of_introspection/index.html#apihelper.divein"]at this link.[/URL] I think you have some typing errors in what you show us but it's hard to tell without the code tags. | |
Re: Do you have a package manager? If you have ActivePerl from ActiveState then you probably have PPM. Just type [icode]ppm[/icode] at the command prompt and PPM starts up with a GUI. I don't know if that will solve the problem, but package managers are an alternative way to install binaries … | |
Re: Here's my 2 cents on what [ICODE](not year%4 and year%100 or not year%400) and True[/ICODE] is doing. Python knows it is evaluating a Boolean expression and so it evaluates as much as it needs to, evaluating each component expression according to the rules of precedence, until it get a definite … | |
Re: The brute force approach is maybe not so bad since you don't have to lower the entire dictionary, just the string of its keys.[code]>>> d = {'Spam': 2, 'Ham': 1, 'Eggs': 3} #Here is a dictionary >>> s = str(d.keys()) #Here is a string of its keys >>> 'ham' in … | |
Re: I agree with mitchems. Just as a further note, the mistake may have included putting the cgi scripts in the same directory as the html documents. Simon Cozens warns against this (even if you succeed in making them executable).[QUOTE]The reason for keeping scripts out of the document hierarchy is to … | |
Re: This worked OK for me after commenting out a couple of print statements that were trying to send output to the web page before printing the html header.[CODE]#!/usr/bin/perl use strict; use warnings; use POSIX qw(strftime); my $output; my $cur_time = strftime "%a %b %e %H:%M:%S %Y", localtime; #print "$cur_time\n"; #Don't … | |
Re: Could you attach a copy of data_file_1.dat to your post? Or if you could post some of the data (within code tags) it would make it easier to help you with this. | |
Re: The following should edit and save a.config and create a backup copy of the original named a.config.old[CODE=bash]perl -pi.old -e 's/(CLUSTER_NAME\t\t)cluster1/$1autocluster/' a.config[/CODE] | |
Re: [QUOTE=Graffixnerd;1211800]I want to calculate somebody date using his/her Date of Birth which is located on the database column name(DOB)..which sql function do i use and how do i use it on the Sqlquery..please help[/QUOTE] To write a query that shows somebody's date of birth you don't need a function. Assuming … | |
Re: Where in your schema do you record the fact that the student is taking, or has taken some courses? I think you need a table that has a one-many relation associating each student to courses that student is taking or has taken. StudentCourses ([U]studentid[/U], [U]courseid[/U], date_completed) | |
![]() | Re: [QUOTE=ghost_from_sa;1212385]... this is what you sugested however wouldnt the + in this be considered as one or more and the . be conisderd as anying? would you not have to escape it with \[/QUOTE] [ICODE]testVar=/^[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/[/ICODE] No, in the above pattern the [ICODE].[/ICODE] is just a dot indicating the possibility of … ![]() |
Re: You may want to look at [URL="http://svn.w4py.org/ZPTKit/trunk/ZPTKit/htmlrender.py"]http://svn.w4py.org/ZPTKit/trunk/ZPTKit/htmlrender.py[/URL] I haven't tested it, but it does look like it uses HTMLParser to do what you want. | |
Re: [ICODE]if ($record =~ m/BUNP:\s*(.*)$/) { #Allow optional space, then capture to end of line[/ICODE] | |
Re: Instead of using separate scalar constants you could use an array of constants that you can iterate through.[CODE]#!/usr/bin/perl use strict; use warnings; # Use a constant array instead of separate constants use constant SERVERNAMES => qw(//firstserver/somedir/ //secondserver/somedir/ //thirdserver/somedir/); foreach my $srvr (SERVERNAMES) { print "$srvr \n"; }[/CODE] | |
Re: Try adding the following to the validate function.[CODE] var ccnum = document.getElementById("credit card number").value; var alldig = false; alldig = /^\s*\d+\s*$/.test(ccnum); //Consecutive digits, optional leading or trailing spaces if (alldig == false) { alert("Credit Card Number must consist of numbers only"); return false; }[/CODE] | |
Re: os.popen returns an object that you can assign to a variable and iterate through. I read about it at [URL="http://linux.byexamples.com/archives/366/python-how-to-run-a-command-line-within-python/"]http://linux.byexamples.com/archives/366/python-how-to-run-a-command-line-within-python/[/URL] [CODE]>>> import os >>> f=os.popen("ls -la") >>> for i in f.readlines(): print "myresult:", i, myresult: total 9804 myresult: drwxr-xr-x 55 david david 4096 2010-05-04 16:28 . myresult: drwxr-xr-x 3 root … | |
Re: [CODE]#!/usr/bin/env python import re DataDir = '/home/david/Programming/Python' phonefile = DataDir + '/' + 'PhoneNumbers.txt' """Read each line from file. If it starts with a string of exactly 10 consecutive digits, assume this is a phone number and print it.""" ph_nbr_pattern = r'^(\d{10})(?:\s|$)' compile_obj = re.compile(ph_nbr_pattern) file2read = open(phonefile, 'r') for … | |
![]() | Re: Why not do it as follows? `my ($oct1, $oct2, $oct3, $oct4) = ($1, $2, $3, $4);` After all, you wrote the regular expression, so you know it returns four matched groups. The sites you googled may be addressing the situation where programmers don't know how many data items they may … |
![]() | Re: Thanks [B]tonyjv[/B] for the clarification and the test data.[CODE]#!/usr/bin/env python import re def FindName(name,list1): """ searches for a pattern in the list, returns the complete list entry(s) as a string. Is case sensitive. """ mlist = [] pattern = r"""^(%s.*)$""" % (name) for item in list1: match = re.search(pattern, item) … |
Re: [CODE=javascript]<html> <head> <title>moje vezbanje</title> <script type="text/JavaScript"> <!-- /* Delete the test() function from between the <body> tags and place it here between the <head> tags */ function test() { alert('123123'); } //--> </script> </head> <body onload="alert('sdfsfd')"> <script type="text/javascript"> //alert("jhgfgh"); function klasa() { var nazivLinka = document.getElementById("prvo").value; var url = document.getElementById("drugo").value; … | |
Re: [CODE]#`cat $Header_File $Detail_File $Trailer_File > $CH_Report`; #Instead of the above `cat ... etc. do the following open OUT, '>', $CH_Report or die "Cannot open $CH_Report $!"; open IN, '<', $Header_File or die "Cannot open $Header_File $!"; while (<IN>) { print OUT $_; } print OUT "\n"; #Newline between header and … | |
Re: If you use findall instead of search you get a list of strings.[CODE]>>> import re >>> MyStr = "<test>some text here</test> <other> more text </other> <test> even more text</test>" >>> m=re.compile('<test>(.*?)</test>', re.DOTALL).findall(MyStr) >>> print m ['some text here', ' even more text'] >>> [/CODE][QUOTE=daviddoria;1199098]Sounds like that will definitely help down … | |
Re: I don't know about SQL loader but have you tried the usual way of assigning the result of Perl commands? For example if I wanted to show the result of executing the print command I would do this:[CODE]my $result = print "hello world\n"; print $result;[/CODE] which shows that the print … | |
Re: Not sure if you intended to allow a space between the colon and $v or not. Assuming not, the following should work.[CODE]#!/usr/bin/perl #Regex.pl use 5.006; use strict; use warnings; #Assign some values to variables and build request string my $k = 'kryptonite'; my $v = 'valium'; my $valid = 1; … | |
Re: [QUOTE=daniels1;1196617]Hi i want to install this cpan CPAN-1.9402.tar.gz Crypt-Rijndael-1.09.tar.gz the prblem is t install it from /tmp and not networking Thanks Danny[/QUOTE] In the book [B]Beginning Perl[/B] look in Chapter 10. There's an example of installing from a downloaded archive. [URL="http://books.simon-cozens.org/index.php?title=BP10&redirect=no"]Chapter 10 is available online from here[/URL] so just search … |
The End.