Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Nevergirls
Jul 4, 2004

It's not right living this way, not letting others know what's true and what's false.

syphon posted:

I keep trying to get into Catalyst or Plack

You say this like Catalyst and Plack are conceptually close. They are not.

Plack is a web server interface. You have a web application that talks Plack, and it can run on any server that understands Plack. It makes deploying web applications dead easy. This is similar to (and named after) Rack in the ruby world.

Catalyst is a web framework. It gives you tools to write web applications. (So does CGI.pm, albeit tools that were crummy by even 1998 standards.) Catalyst talks Plack, so you can deploy it on any server that understands it.

Stuck in a CGI-only environment? Plack::Handler::CGI to the rescue. Yes, even you can run complex web applications with the breathtaking speed afforded by CGI.

Adbot
ADBOT LOVES YOU

Ninja Rope
Oct 22, 2005

Wee.
I like a lot of control and don't really trust stuff like DBIx::Class. What's the best web framework to use that lets me write my own SQL, account management, etc?

TiMBuS
Sep 25, 2007

LOL WUT?

I like Mojolicious, or Dancer for smaller stuff. Catalyst is pretty solid too.

I actually don't know of many web frameworks that force you to use a specific type of ORM or session cache or template engine etc. Maybe jifty?

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Ninja Rope posted:

I like a lot of control and don't really trust stuff like DBIx::Class. What's the best web framework to use that lets me write my own SQL, account management, etc?
Try starting out with Web::Simple. It gives you enough Tools so you can write small web apps off the bat; but is also solid enough that you can write your own Framework on top of it, including whatever request parameter/session/database/renderer interaction you wish.

Edit: Mojolicious isn't a very good choice when you want control over your tools, since a bunch of things, like Mojo::JSON are hard-coded in it.

Mithaldu fucked around with this message at 10:15 on Jan 19, 2012

Wheelchair Stunts
Dec 17, 2005

Ninja Rope posted:

Or CGI::Stateless, CGI::Session, CGI::Cookie, HTML::Template, and AnyEvent::FCGI? :whatup:

Woah, I've used AnyEvent quite a few times in the past. I didn't know there was an AnyEvent::FCGI :getin:

Rohaq
Aug 11, 2006
I'm now looking into Catalyst, which apparently has a DBI submodule.Iif it works any better than the standard DBI module, it might be useful.

Digging for tutorials now.

mister_gosh
May 24, 2002

I have a requirement to replace characters in a given string so that it only contains A-Za-z0-9.-_

Can anyone point me in the right direction? Thanks in advance!

code:
$name = "Bill ( $tickers ) i$ innoc3nt!!"; 

while($name contains something other than /A-Za-z0-9\._\-/) {
    $name =~ s/BAD_CHARACTER/\-/;			
}

print "$name\n";
Bill----tickers---i--innoc3nt--

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
pre:
$name =~ s/[^A-Za-z0-9.-_]/-/g

mister_gosh
May 24, 2002

Wow, thank you. I thought it was going to be much more complicated (substrings, looping, etc.). I switch between too many languages (the worst, of which, is XSLT).

Thanks!

RICHUNCLEPENNYBAGS
Dec 21, 2010
code:
 given ($itunesopen) {
   when ('y') {
     foreach (@mp3files)
       system "open", "-a", "\/Applications\/iTunes.app\/", $_ ;
   }
   default {
     die
 }
 }
I guess there's something wrong with this system call, but I'm not sure what (I've fiddled with it a bit but can't get it to compile). What am I doing wrong?

code:
syntax error at ./tracktypegrab.pl line 143, near ")
        system"
Execution of ./tracktypegrab.pl aborted due to compilation errors.
edit: posting this was what I needed to see that missing bracket I guess. D'oh.

I'm just consoling myself with the fact that I've only been doing it for a week or two.

RICHUNCLEPENNYBAGS fucked around with this message at 10:57 on Jan 22, 2012

MacGowans Teeth
Aug 13, 2003

How do you make a module save configuration data? I have a module that ideally should read a data dictionary once, save it, and use it from then on out. Right now I'm using File::Save::Home, but I don't know if that's the best way to go about it. What are my options here? When I search for modules and configuration files, I get nothing but results about modules that can read configuration files, which is not what I want - I want to be able to write configuration data to be read the next time the module is used.

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

Sizzler Manager posted:

How do you make a module save configuration data? I have a module that ideally should read a data dictionary once, save it, and use it from then on out. Right now I'm using File::Save::Home, but I don't know if that's the best way to go about it. What are my options here? When I search for modules and configuration files, I get nothing but results about modules that can read configuration files, which is not what I want - I want to be able to write configuration data to be read the next time the module is used.

If you like XML, you can use XML::Simple.

MacGowans Teeth
Aug 13, 2003

prefect posted:

If you like XML, you can use XML::Simple.
Actually, what I'm getting confused about is more basic - I can't figure out how to get the module to save a file in a predictable place without giving it a hardcoded path. This is probably a pretty stupid question, but that's where my issue is - how do I get the module to save its own data in a directory relative to the module's location?

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Sizzler Manager posted:

Actually, what I'm getting confused about is more basic - I can't figure out how to get the module to save a file in a predictable place without giving it a hardcoded path. This is probably a pretty stupid question, but that's where my issue is - how do I get the module to save its own data in a directory relative to the module's location?

You can use Findbin for this. Also: gently caress XML and especially XML::Simple. You don't want it for this task at all. Use either YAML or JSON for serialization into readable formats.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Acme::State is exactly the solution to everyone's problems.

leedo
Nov 28, 2000

File::HomeDir (does this still pull in a ton of awful Carbon modules) + serializer of choice?

welcome to hell
Jun 9, 2006
File::HomeDir uses Mac::SystemDirectory now, which doesn't depend on any non-core modules.

If you actually want to use a directory relative to the current module (and not the currently running script or home directory) __FILE__ will give you the path to the currently compiling file. You almost certainly want to run it through File::Spec->rel2abs outside any subs though, to protect against possible directory changes.

File::ShareDir is probably a better approach for module or dist configuration data.

MacGowans Teeth
Aug 13, 2003

Haarg posted:

File::HomeDir uses Mac::SystemDirectory now, which doesn't depend on any non-core modules.

If you actually want to use a directory relative to the current module (and not the currently running script or home directory) __FILE__ will give you the path to the currently compiling file. You almost certainly want to run it through File::Spec->rel2abs outside any subs though, to protect against possible directory changes.

File::ShareDir is probably a better approach for module or dist configuration data.
Thanks! All these responses have also introduced me to some nice modules I didn't know about, too. :)

uG
Apr 23, 2003

by Ralp

quote:

DBIx::Class::ResultSet::count(): DBI Connection failed: DBI connect('rivals','root',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) at /usr/local/share/perl/5.10.1/DBIx/Class/Storage/DBI.pm line 1248 at starter_ref_add.pl line 4
I had a few scripts running when I got this error on all of them. Now I can't do anything database related in Perl without getting that error. Everything else can access the database file still. /var/run/mysqld/mysqld.sock exists, and I tried changing my connect args to use TCP, but still no connection.

So i'm assuming this is a Perl problem and not mysql. I've reinstalled mysql anyway, and also all the Perl DB modules, and am still at square 1. What should I try next?

uG fucked around with this message at 22:11 on Mar 8, 2012

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
If you're trying to connect to localhost, try connecting to 127.0.0.1 instead. MySQL has a stupid thing where it forces socket connection when it sees localhost, even if you asked for a port.

uG
Apr 23, 2003

by Ralp

Mithaldu posted:

If you're trying to connect to localhost, try connecting to 127.0.0.1 instead. MySQL has a stupid thing where it forces socket connection when it sees localhost, even if you asked for a port.
Yea i've tried that, still no go. If I use plain DBI I can access the socket. So it must be DBIx::Class related (and also with count)... I just don't see how it could have happened on its own :psyduck:

uG fucked around with this message at 22:31 on Mar 8, 2012

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

uG posted:

Yea i've tried that, still no go. If I use plain DBI I can access the socket. So it must be DBIx::Class related (and also with count)... I just don't see how it could have happened on its own :psyduck:

In that case i'd suggest getting on irc.perl.org and bothering ribasushi.

Ninja Rope
Oct 22, 2005

Wee.
Or strace and look for calls to open/connect/whatever unix sockets use?

Boldor
Sep 4, 2004
King of the Yeeks
I don't do much coding, so pardon the potential :downs: in this post.

I'm parsing a text file. One column in my data always contains a positive integer, but not all of them are encoded as, say, 1080; a few are encoded as " 1,080 ". (This is an actual example from my input file, including the pair of double quotes.)

No problem, right? I'll just strip everything that's not a digit, like so:

code:
$foo[4] =~ s/[^0-9]//g;
However, $foo[4] stubbornly remains " 1,080 " rather than reducing to 1080 as desired.

Why is this happening, and what am I doing wrong?

het
Nov 14, 2002

A dark black past
is my most valued
possession
That line works for me:

code:
$ perl -e '$foo = " 1,080 "; $foo =~ s/[^0-9]//g; print "$foo\n";'
1080
Is that the exact line of code?

syphon
Jan 1, 2001
Why not use \d+ instead? Not sure it'll help whatever problem you're having, but seems simpler.

Boldor
Sep 4, 2004
King of the Yeeks

Het posted:

That line works for me:

code:
$ perl -e '$foo = " 1,080 "; $foo =~ s/[^0-9]//g; print "$foo\n";'
1080
Is that the exact line of code?

Using exactly this code in a loop that reads in all data from the text file:

code:
    $atrrib[4] =~ s/[^0-9]//g;        # strip all nondigits
    print $attrib[4],"\n";
results in output where $attrib[4] appears completely unchanged from the source text, including " 1,080 ".

syphon posted:

Why not use \d+ instead? Not sure it'll help whatever problem you're having, but seems simpler.

This doesn't work either.

For the record, the statement currently right above it is:

code:
    $attrib[2] =~ s/Pesant/Peasant/g; # common misspelling in data file
and that does work as expected.

Another thing that I didn't realize before might be a problem is that I'm running an ancient version of Perl. It's v5.8.7, running on Windows XP, if that makes any difference. I didn't realize I was that behind the times! I'll try an update and see if that makes this mysterious problem vanish, and edit in results.

edit: Upgrading to v5.14.2, build 1402, Windows XP for x86, does not fix the problem. I used the binary from ActiveState, if that makes any difference.

Boldor fucked around with this message at 05:41 on Apr 18, 2012

het
Nov 14, 2002

A dark black past
is my most valued
possession

Boldor posted:

Using exactly this code in a loop that reads in all data from the text file:

code:
    $atrrib[4] =~ s/[^0-9]//g;        # strip all nondigits
    print $attrib[4],"\n";
results in output where $attrib[4] appears completely unchanged from the source text, including " 1,080 ".


This doesn't work either.

For the record, the statement currently right above it is:

code:
    $attrib[2] =~ s/Pesant/Peasant/g; # common misspelling in data file
and that does work as expected.

Another thing that I didn't realize before might be a problem is that I'm running an ancient version of Perl. It's v5.8.7, running on Windows XP, if that makes any difference. I didn't realize I was that behind the times! I'll try an update and see if that makes this mysterious problem vanish, and edit in results.
Oh man I hope this isn't it but notice that in:

code:
    $atrrib[4] =~ s/[^0-9]//g;        # strip all nondigits
    print $attrib[4],"\n";
the first line says "atrrib" and the second line says "attrib"

If that's the problem I have 4 words for you: Always use strict goddammit!!!

Boldor
Sep 4, 2004
King of the Yeeks

Het posted:

Oh man I hope this isn't it but notice that in:

code:
    $atrrib[4] =~ s/[^0-9]//g;        # strip all nondigits
    print $attrib[4],"\n";
the first line says "atrrib" and the second line says "attrib"

If that's the problem I have 4 words for you: Always use strict goddammit!!!

Yes, that's it. :cripes:

Dammit I knew it was something stupid like that.

Anaconda Rifle
Mar 23, 2007

Yam Slacker

Het posted:

If that's the problem I have 4 words for you: Always use strict goddammit!!!

Seriously, if anyone asks a question without using strict and warnings in their code, they're wasting our (moderately well-paid) time.

MacGowans Teeth
Aug 13, 2003

Anaconda Rifle posted:

Seriously, if anyone asks a question without using strict and warnings in their code, they're wasting our (moderately well-paid) time.

I've run into that kind of problem using strict (variable doesn't have anything like the expected return value), but it usually ends up being because I accidentally localized a variable when I was moving things around. :doh:

MacGowans Teeth
Aug 13, 2003

What's the deal with the "universal->import is deprecated" warning? I've searched around for this, and it's apparently a practice that you're not supposed to use which was deprecated in 5.12, but what is it and why were people using it? There's a module I'm interested in using or modifying for my own purposes (Brick by brian d foy), but among other things, trying to install it gives me a bunch of deprecation warnings for whatever that is.

Roseo
Jun 1, 2000
Forum Veteran

Sizzler Manager posted:

What's the deal with the "universal->import is deprecated" warning? I've searched around for this, and it's apparently a practice that you're not supposed to use which was deprecated in 5.12, but what is it and why were people using it? There's a module I'm interested in using or modifying for my own purposes (Brick by brian d foy), but among other things, trying to install it gives me a bunch of deprecation warnings for whatever that is.

http://perldoc.perl.org/UNIVERSAL.html#EXPORTS, most likely.

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Anaconda Rifle posted:

Seriously, if anyone asks a question without using strict and warnings in their code, they're wasting our (moderately well-paid) time.

In case it's not common knowledge, "Use Modern::Perl" will use Strict, Warnings and specific 5.10+ features. Shortcut to enable all of these.

MrL_JaKiri
Sep 23, 2003

A bracing glass of carrot juice!
I'm currently (re)learning Perl and am writing my first proper program. This is more of a philosophical question than a practical question, I'm just wondering if there's any way I can make the method I'm using more elegant and/or efficient.

What I have is a file with two reasonably large (~12k) lists of numbers in them (properties of a chemical). I'm characterising the chemical by making a 2d histogram - ie if the two lists read 1 1 1 and 4 4 6 I'll have 2 at (1,4) and 1 at (1,6).

At the moment I'm reading the file into two arrays of argument 0-whatever and for each value of the argument adding 1 to the respective histogram array where the coordinate (form: xy) is the argument - so histogram[14] = 2 using the earlier example.

Most of the end result of the histogram is going to be white space, so I can't just print the whole thing out. So I make it print out in the format coordinate: value iff the value stored in the array is nonzero.

There's a maximum number of coordinates of about 36000, so brute forcing it won't be too inefficient,

If you'd like to see my code I can do that (it's on a lab computer that I don't want to log into SA on :v: ), but in terms of writing the code I'd like to make my own mistakes (for now!) and I'm more asking in case there's a more elegant way of doing things that I've missed.

baquerd
Jul 2, 2007

by FactsAreUseless

MrL_JaKiri posted:

What I have is a file with two reasonably large (~12k) lists of numbers in them (properties of a chemical). I'm characterising the chemical by making a 2d histogram - ie if the two lists read 1 1 1 and 4 4 6 I'll have 2 at (1,4) and 1 at (1,6).

At the moment I'm reading the file into two arrays of argument 0-whatever and for each value of the argument adding 1 to the respective histogram array where the coordinate (form: xy) is the argument - so histogram[14] = 2 using the earlier example.

Are you sure histogram[X] is unique? What happens on (21, 1) versus (2, 11)?

There's nothing terribly wrong with your methodology other than that collision possibility. I'd probably have implemented it as a hash of hashes, which would save you a bit of memory and cost you a bit more CPU when you read out the histogram, but ultimately it's not that important for this size data set on modern hardware.

MrL_JaKiri
Sep 23, 2003

A bracing glass of carrot juice!

baquerd posted:

Are you sure histogram[X] is unique? What happens on (21, 1) versus (2, 11)?

Good point;

All the information is to 3sf so I'll explicitly make the combination include leading zeros - so 21001 vs 2011 (leading zeroes in x implicit for the argument, explicit when I print the argument to file so 021001 vs 002011).

Cheers

MrL_JaKiri
Sep 23, 2003

A bracing glass of carrot juice!
Another dumb question, but I seem to remember there being a way to make programs be more sequential;

ie consider a file with A, B, C in it.

What I want is to be able to append, say, D to the file (so that on the disk it says A, B, C, D) and then later in the same program print the file such that it displays A, B, C, D rather than the value of the file (A, B, C) that was the case when the program was created.

[edit]

Thanks to both of you

MrL_JaKiri fucked around with this message at 16:19 on May 16, 2012

Ninja Rope
Oct 22, 2005

Wee.
I don't understand what you're asking. After you open a file you can append to it by seek()'ing to the end before writing. If you want to re-read that file from the start with the data you appended, seek() to the beginning before reading.

Adbot
ADBOT LOVES YOU

qntm
Jun 17, 2009

MrL_JaKiri posted:

Another dumb question, but I seem to remember there being a way to make programs be more sequential;

ie consider a file with A, B, C in it.

What I want is to be able to append, say, D to the file (so that on the disk it says A, B, C, D) and then later in the same program print the file such that it displays A, B, C, D rather than the value of the file (A, B, C) that was the case when the program was created.

code:
use Fcntl;
open my $fh, ">>", $filename or die "urk"; # open for append
print $fh "D";
seek $fh, 0, Fcntl::SEEK_SET; # seek to start of file
print readline $fh; # print the whole thing
close $fh;

  • Locked thread