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.
 
  • Post
  • Reply
JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

kruna posted:

I have a question about C++. First though I wanna provide some of my background so you know where I'm coming from. Basically I studied Java for 2 years in high school, then after that I studied some C++ on my own. I can read C++ very well and I've done some programming, but I haven't actually done any programming in a while. Recently I got hired at my university to help a professor with her physics research. I run and maintain this clunky Fortran (I learned on my own from the ground up) program we use to crunch numbers, Fortran is great for number crunching but I just don't feel comfortable doing some things with it. And well, I think I could save us some time if I could program something on top of Fortran, using C++. So I need someone to point me in the right direction I need to go to learn how to run another program via C++. Just some commands and a tutorial link would be greatly appreciated. I can figure out the rest on my own probably. Thanks in advance goons

I'd say you're best-off using Python as the high-level controller that launches the Fortran tasks. It's really easy to pick up, much less cryptic than C++ and good for writing things rapidly. There might be a specific Python-Fortran interface, but if not, use the subprocess module.

If you really want to use C++, I'd suggest using Qt and the QProcess class which is cross-platform and has a nice clean, high-level API.

Adbot
ADBOT LOVES YOU

maskenfreiheit
Dec 30, 2004
.

maskenfreiheit fucked around with this message at 21:27 on Apr 28, 2019

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
I don't even know where to start. You're putting HTML in CSS files, using C-style comments in HTML, you're trying to import the CSS twice, and I'm not even sure what you're trying to do with the font styles.

I have a theory, and that theory is that the book you got isn't worth the paper it's printed on. Just use http://www.w3schools.com/ and save yourself the headache.

kruna
Jun 6, 2006
I missed the rapture.

JoeNotCharles posted:

I'd say you're best-off using Python as the high-level controller that launches the Fortran tasks. It's really easy to pick up, much less cryptic than C++ and good for writing things rapidly. There might be a specific Python-Fortran interface, but if not, use the subprocess module.

If you really want to use C++, I'd suggest using Qt and the QProcess class which is cross-platform and has a nice clean, high-level API.

Hey thanks, I'll think about giving python a shot actually, since I've been tutoring another one of our research assistants in python (python comes highly recommended to teach people as their first programming language) I could probably get him involved and give him more experience.

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe
This is probably stupid, but:

Should local variables be avoided on a function that's called an upwards of 100 times a second?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

slovach posted:

This is probably stupid, but:

Should local variables be avoided on a function that's called an upwards of 100 times a second?

Generally, no. In a compiled language, local variables are mostly an abstraction for expressing how data flows through a function, and using "extra" variables will often make absolutely no difference in the final code. Interpreters don't necessarily have the flexibility to get away with that, so you might pay for using "too many" locals with a little extra memory overhead. Regardless, it is almost guaranteed to not cause a substantial performance impact.

If you are absolutely dying for performance, and you have done everything else in your power, and you are absolutely certain that a function is a hotspot, and you magically know that a variable is not going to be allocated into a register, and you are writing a non-reentrant function in non-PIC code on the right sort of architecture, then it can sometimes improve performance to declare a local variable static rather than auto. But you should probably just forget I ever said that.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Also, 100 times a second is not very often.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

rjmccall posted:

Generally, no. In a compiled language, local variables are mostly an abstraction for expressing how data flows through a function, and using "extra" variables will often make absolutely no difference in the final code.

Sure it will. In most languages, local variables get pushed onto the call stack, so you'll be dealing with a (very) small but measurable cost to memory. Chances are you're not going to be losing much (if anything) in the way of speed, though.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Avenging Dentist posted:

Sure it will. In most languages, local variables get pushed onto the call stack, so you'll be dealing with a (very) small but measurable cost to memory. Chances are you're not going to be losing much (if anything) in the way of speed, though.

But that's exactly what I'm talking about : in an optimizing compiler, local variables are mostly just an abstraction for describing how data flows through a function. If your extra variable actually alters the mechanics of the function such that more data is suddenly flowing around, then sure, you're increasing register pressure, and you might force things onto the stack. But I'm assuming we're talking about equivalently-written functions, except that one of them is naming its temporaries or its constants or something.

That is, if your optimizer doesn't compile this:
code:
int five = 5;
int a = foo();
float b = bar(a);
return baz(b, five);
into the same result as this:
code:
return baz(bar(foo()), 5);
then you really, really need a new optimizer.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
I was referring to the more general case of non-POD types with (not quite) equivalent code (C++):

code:
// 1
string foo = get_foo();
string bar = get_bar();
do_foo(foo);
do_bar(bar);


// 2
do_foo(get_foo());
do_bar(get_bar());

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Okay, sure, yeah. I was definitely just thinking about POD types. In my defense, very few languages have stack-allocatable types with opaque construction/copying semantics.

maskenfreiheit
Dec 30, 2004
/

maskenfreiheit fucked around with this message at 03:58 on Sep 29, 2010

Jo
Jan 24, 2005

:allears:
Soiled Meat
Can someone recommend a book on computer vision and feature extraction? I've got a lot of calculus and enough linear algebra to tackle formula-intensive materials if need be, but I'd prefer something a little more 'fun'. I'm leaning towards "Computer Vision: A Modern Approach", but I'm interested in whatever anyone else has to say on the subject.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

GregNorc posted:

code:
ul#[i]list-menu[/i] li a {

This is your problem

Mask
Jun 8, 2003
Quis Custodiet Custodes Ipsos?
I am very new to programming and am having the most difficult time with this C problem.

code:
#include <stdio.h>

int main()       {
    
    int STATE, VOTES, NUM_STATES, MAX_VOTES, TOP_STATE;
    TOP_STATE = 0;
    STATE = 1;
    MAX_VOTES = 0;
    
    printf("How many states are you entering?\n");
    scanf("%d", &NUM_STATES );
    
    for (STATE=1; STATE <= NUM_STATES; STATE++)       {
      
          printf("How many electoral votes does state %d have?\n", STATE);
          scanf("%d", &VOTES);
          
      if (VOTES > MAX_VOTES)
          MAX_VOTES = VOTES;
       
     if (STATE > TOP_STATE)  
         TOP_STATE = STATE;                 
}
       
        
    printf("State %d is the most important with %d electoral votes.\n", TOP_STATE, MAX_VOTES);

       
      
    system("PAUSE");
    return 0;
    
}
I have to somehow pull out that the number of the state entered with the highest electoral votes is what will be outputted instead of just the highest value inputted for TOP_STATE.

Mask fucked around with this message at 02:54 on Sep 24, 2008

csammis
Aug 26, 2003

Mental Institution
Think about it logically. You're saying "If the entered number of votes is larger than the current maximum, record the new vote number," then you're saying "If the state is larger than the 'max' state, record the new state." You want to say "If the entered number of votes is larger than the current maximum, record the new vote number and save the current state."

Lexical Unit
Sep 16, 2003

Use the [code] tags to format your code, pretty please. :)

Beyond thinking about it logically, trace out the code you've written so that you can get a better understand of what's happening.

Trace the value for STATE in your for loop. First it starts out as 1, and then it get incremented once each iteration, and the loop exits when STATE is greater than NUM_STATES. So by that logic at the end of the loop STATE = 1 + NUM_STATES, and TOP_STATE = NUM_STATES. I doubt this is what you're trying to accomplish.

Look at how you calculate MAX_VOTES. Whenever you get some number of votes that's greater than your current maximum, you set the maximum to that value. Ok, so you want to know which state it was that triggered this. So the condition that determines when you should be setting MAX_VOTES is the exact same condition that determines when you should be setting TOP_STATE. See?

Also, all capital symbols are typically used only for macros. It's very distracting to see all capitals used for variables like that.

Mask
Jun 8, 2003
Quis Custodiet Custodes Ipsos?
Seems like I have some bad style there, glad I am new to this and its not yet permanent! Also, I will try to remember the [code] thanks. I understand what you guys are trying to convey to me but I think me sitting here banging my head against my desk in the computer lab for the last two hours has me to frustrated to even work this out logically. I think I have to do some sort of if statement that maybe equals itself from top state to best votes but I just can't seem to put it together.

Mask fucked around with this message at 02:54 on Sep 24, 2008

csammis
Aug 26, 2003

Mental Institution

Mask posted:

I think I have to do some sort of if statement that maybe equals itself from top state to best votes but I just can't seem to put it together.

All you need to do is test the number of votes, and save both the highest number of votes and the state with that number. Once you get a new highest number of votes, you can overwrite the previous state with the new current state.

And if you don't know:

code:
if(i == 0)
  execute_one_statement;

if(i == 1)
{
  one_statement;
  two_statements;
}
Note that the braces let you do more than one thing "under" a single if statement.

tripwire
Nov 19, 2004

        ghost flow
This is a really noob question but having been using python for a while I've gotten used to painless string handling, and now that I'm working on something in C I'm scratching my head as to how the proper way to handle strings is. I also am hopelessly lost on how or when to do proper garbage collection which compounds my problem.

I want a function to return an immutable string (or two) to another function. I know its possible to have the parent function declare and initialize strings and have the inner function fill in the string by reference, but it seems really ugly to have my code littered with strings which could be null or could be meaningful depending on the circumstances. I know that for a function variable to persist after the functions scope you need to declare it static, but I have no idea what this means for garbage collection or dynamically allocated strings. I also don't like the idea of making lots of global variables. In c, how should I be declaring strings, and when should I make them dynamically allocated? How should I return strings from functions? Which of the following makes sense inside a function:
char * my_string;
char my_string[100];
char * my_string = (char *) xmalloc(100);

If my inner function returns a pointer to a const string do I have to worry about garbage collection? What if this function gets called a million times, will it be making a million static strings in memory that stay forever?

CISADMIN PRIVILEGE
Aug 15, 2004

optimized multichannel
campaigns to drive
demand and increase
brand engagement
across web, mobile,
and social touchpoints,
bitch!
:yaycloud::smithcloud:
I have a program (it can barely be called that) I have write to send out to 1200 Windows users because our software vendor is to lazy to fix a bug. I don't think I need help in how to code it, just what language/tools will be the quickest and easiest to write and distribute. I've done a fair bit of programming both in school and professionally, but it's been a few years and there's new poo poo out.

All the program needs to do is to pop up a box saying "enter number" convert that number to hex and use the hex number to find a directory and a file name and then delete that file.

I've never used python before but I assume that it would probably be the easiest to use? I don't really give a poo poo about the size of the downloaded exe and I want to make it as easy as possible for the people who need to run it.

tripwire
Nov 19, 2004

        ghost flow

bob arctor posted:

I have a program (it can barely be called that) I have write to send out to 1200 Windows users because our software vendor is to lazy to fix a bug. I don't think I need help in how to code it, just what language/tools will be the quickest and easiest to write and distribute. I've done a fair bit of programming both in school and professionally, but it's been a few years and there's new poo poo out.

All the program needs to do is to pop up a box saying "enter number" convert that number to hex and use the hex number to find a directory and a file name and then delete that file.

I've never used python before but I assume that it would probably be the easiest to use? I don't really give a poo poo about the size of the downloaded exe and I want to make it as easy as possible for the people who need to run it.

Yes, python would be really simple. Actually I'd recommend autohotkey. Since its built around win32 it has ltos of nice convenience functions and compiles directly to tiny 40kb exe files which you can distribute to people painlessly. The help is well written and it shouldn't take you more than a couple hours to finish really.

Standish
May 21, 2001

tripwire posted:

In c, how should I be declaring strings, and when should I make them dynamically allocated? How should I return strings from functions?
Most common way is for the caller to pass in a buffer (plus a length) for the function to fill out. You can also dynamically allocate a string inside the function and return that, but then the caller has to remember to free it and stylistically it's not as nice.

What you can't do is declare a char[] array inside the function and return that, because that is on the stack and it goes away when your function returns.

quote:

If my inner function returns a pointer to a const string do I have to worry about garbage collection? What if this function gets called a million times, will it be making a million static strings in memory that stay forever?
If by "const string" you mean "a string literal" then no you don't have to worry about garbage collection and no matter how many times you call the function there will only ever be one copy of it.

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

tripwire posted:

In c, how should I be declaring strings, and when should I make them dynamically allocated? How should I return strings from functions? Which of the following makes sense inside a function:
char * my_string;
char my_string[100];
char * my_string = (char *) xmalloc(100);

If my inner function returns a pointer to a const string do I have to worry about garbage collection? What if this function gets called a million times, will it be making a million static strings in memory that stay forever?

C doesn't have garbage collection, so no worries there.

You can use a char array when you won't be using the string outside of the current function. You can pass a char array to another function to fill in, but you can't return a char array from a function. Also, the stack size is limited in compiler-specific ways. As a rule of thumb I don't have more than 512 bytes worth of local variables (the actual limit is something like 3k for VS8 but I'm weird). Finally, you can't use char arrays when you don't know the required buffer size at compile-time.

Use heap-based buffers when you don't know how large of a buffer you'll need until run-time, you need large buffers or if you need the string to persist outside of function scope (e.g. when you need to return a string).

You will very rarely want to declare a local string static.

Finally, you shouldn't cast with malloc() in c.

tripwire
Nov 19, 2004

        ghost flow

Standish posted:

Most common way is for the caller to pass in a buffer (plus a length) for the function to fill out. You can also dynamically allocate a string inside the function and return that, but then the caller has to remember to free it and stylistically it's not as nice.

What you can't do is declare a char[] array inside the function and return that, because that is on the stack and it goes away when your function returns.
If by "const string" you mean "a string literal" then no you don't have to worry about garbage collection and no matter how many times you call the function there will only ever be one copy of it.

Cool, thanks. The reason I'm struggling is because I need a buffer to a read a file into but I don't know how big the buffer needs to be. It could be a small number or a big number depending on the file so I don't know how to declare it.

tripwire
Nov 19, 2004

        ghost flow
Thanks for the pointers plastic jesus. Out of curiosity, what are the dangers in casting the result of malloc?
What I'm actually doing is trying to generate a http/1.0 response which entails assembling a status line, headers, and finally the body of whatever you are sending. Since I'm sometimes sending things of dynamic size (like generated pages) I don't know how big the buffer needs to be until too late. It is really making me appreciate how easy these things are to do in python.

I guess I'll be passing a bunch of pointers to strings around to get the work done, but I'm still confused.
Should I be using malloc to declare strings in the parent function? Or, should I just declare a pointer in the outer function and have the child malloc its own string, passing it to the parent by reference?

tripwire fucked around with this message at 20:40 on Sep 24, 2008

CISADMIN PRIVILEGE
Aug 15, 2004

optimized multichannel
campaigns to drive
demand and increase
brand engagement
across web, mobile,
and social touchpoints,
bitch!
:yaycloud::smithcloud:

tripwire posted:

Yes, python would be really simple. Actually I'd recommend autohotkey. Since its built around win32 it has ltos of nice convenience functions and compiles directly to tiny 40kb exe files which you can distribute to people painlessly. The help is well written and it shouldn't take you more than a couple hours to finish really.

AHK is pretty neat. I'll probably use it.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

tripwire posted:

Should I be using malloc to declare strings in the parent function? Or, should I just declare a pointer in the outer function and have the child malloc its own string, passing it to the parent by reference?

1) I assume your HTTP responses can get large. You seem to have figured this out already, but to be clear: all the advice about stack-allocated char arrays really only applies to fairly small, preferably fixed-size arrays, and for anything larger you really want to be using malloc().

2) Dealing with strings in C involves a lot of obnoxious grunt work with char arrays, and your life will be massively easier if you can use a C++ string class.

3) If you have to use pure C, then you should feel free to use malloc in whatever way is most convenient. However, there's a general rule you should always keep in mind in any language with manually-manged memory: every time you allocate more memory, you should always have a plan for how you're going to free it. If it's not immediately obvious from the code, you might even want to add a comment, like:

code:
/* belongs to the depot_t, freed when depot is resized or destroyed */
depot->missile_bay = malloc(n * sizeof(missile_t))
(note that I didn't need to cast the result of malloc because void* is implicitly convertible to any pointer type and vice-versa).

Applying this rule, there's nothing intrinsically wrong with returning a reference to malloced memory from a function; it just means that the caller has to take responsibility for freeing it (unless you're doing something very tricky). If you can keep that straight, though, there's no reason to avoid it. You do need to avoid things like mixing allocated and unallocated memory; for example, this is bad, because the caller can never know if it's safe to free the result:

code:
  char* copy_string(const char* str) {
    if (int len = strlen(str)) { /* might be a C++-ism, I can never remember */
      char* copy = malloc(len);
      memcpy(copy, str, len);
      return copy;
    }else return "";
  }

Standish
May 21, 2001

tripwire posted:

Thanks for the pointers plastic jesus. Out of curiosity, what are the dangers in casting the result of malloc?
Q: Why does some code carefully cast the values returned by malloc to the pointer type being allocated?
Q: What's wrong with casting malloc's return value?

tripwire
Nov 19, 2004

        ghost flow
Thanks for the helpful responses everyone. One thing I want my progrma to do is store a file into a buffer on the heap, and my difficulty was not knowing the size of the file beforehand. I noticed that the GNU extension function getline and getdelim are able to do this and if your file is bigger than the buffer you provided it just reallocates a bigger buffer for you.
Since these functions seems to be line oriented and I just want to throw every character in a file onto a buffer regardless of delimiters, does anyone know how I can do that? I mainly want the benefit of it dynamically reallocating the buffer for me.

Standish
May 21, 2001

tripwire posted:

Since these functions seems to be line oriented and I just want to throw every character in a file onto a buffer regardless of delimiters, does anyone know how I can do that? I mainly want the benefit of it dynamically reallocating the buffer for me.
Look into mmap(), it allows you to map the entire contents of a file onto memory. Something like this:
code:
int fd = open(filename, O_RDWR);

struct stat s; // for getting the file size
fstat(fd, &s); 

[b]char *contents = mmap(NULL, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0);[/b]
// can now read the "contents" buffer and you're really accessing the underlying file

Standish fucked around with this message at 22:37 on Sep 24, 2008

Nofehr
Sep 14, 2004
The Return of Noinche!
My external HardDrive has been powering down (energy save mode?) and cutting my music off when it instantly realizes it should do this because it is streaming music and boots back up.

Someone recommended that I do this in Terminal (yes im a mac user)
code:
pmset -a spindown 30
0=Never
will that work? I want my drive to stay powered up while I use it to stream music, but i don't want it to never power down/save energy.

RheinholdMessner
May 12, 2001

by Fistgrrl
Does anyone know of any basic tutorials or introductions to APL?

csammis
Aug 26, 2003

Mental Institution

Nofehr posted:

My external HardDrive has been powering down (energy save mode?) and cutting my music off when it instantly realizes it should do this because it is streaming music and boots back up.

Someone recommended that I do this in Terminal (yes im a mac user)
code:
pmset -a spindown 30
0=Never
will that work? I want my drive to stay powered up while I use it to stream music, but i don't want it to never power down/save energy.

This isn't coding. Tech support goes here, but it looks like you already know that :crossarms:

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

tripwire posted:

Thanks for the helpful responses everyone. One thing I want my progrma to do is store a file into a buffer on the heap, and my difficulty was not knowing the size of the file beforehand.

Use fseek() to move to the end of the file, then ftell() to get the size of the file. Then just malloc(), fseek() back to the beginning of the file, and read it all in one shot.

Rhusitaurion
Sep 16, 2003

One never knows, do one?
Question for those familiar with Erlang:

What's the usual way of implementing a lookup table in Erlang? I just want to convert between ASCII and EBCDIC, and a simple 256-entry lookup table is the usual way, but I can't figure out how it's done.

blueninja
Sep 24, 2005

I want to develop a client/server app where the clients would run both on a desktop (standalone app and/or website) and on a cell phone (j2me midp 2.0) and I'd like some suggestions for development platforms and other technologies. This is a hobby project and would most likely just be used by myself and maybe a friend or two. It's mostly an excuse to try out writing stuff for j2me anyway. Since it will be able to have multiple clients I'd like to be able to talk to the server quite often so the clients stay up to date but that leads to a lot of bandwidth being used which is expensive on cell phones (I pay about $2 per megabyte) so if possible I'd like to keep it down.

I've put together a small webservice in .net and written a small client in j2me-java in netbeans and that worked quite well. This looks like a nice approach in that it was really slick, the IDEs generated code that made it really smooth. Another good thing about this is that my friend who'll be writing this with me likes working with visual studio and c# and it gives me a chance to learn some c# as well as I've never touched it before. The biggest draw of this solution is that it was so smooth to develop with all the support we got from the IDE, since this is a hobby thing it's nice not having to do a lot of boring communications coding on your spare time, we get enough of that at work :) .. The drawbacks are 1) the webservice/soap stuff uses a lot of bandwidth and 2) finding a cheap web host that can run the .net 3.5 stuff isn't that easy. Of those two, number 1 is by far the biggest one, I'm sure I could either find some host for it or host it myself on my home connection, it's not like this is anything really critical. There is also the option of developing the service in java but I suppose it has the same drawbacks as .net (hosting) and quite frankly I'd rather go with .net as it's new to me and java isn't.

Another option would be to write some web service thing in php but quite frankly, after looking at php, I'd rather not touch it with a 10-ft pole, it looks horrible. The good thing about this however would be that it would be easier to host it, I already have a web host that can do php. I guess the same problem with bandwidth would still apply. I don't know if there are any nice tools for php-development that could help out with the service stuff but either way there's a bit of logic on the server side that I'd have to write. This option doesn't seem so appealing unless someone could point me to something that'd make php development less painful.

Then there's the third option of skipping the web service stuff and writing some sort of homebrew network communications code. This could cut down on the bandwidth substantially but I'm guessing at a significant cost of development time (and a lot of this coding would be stuff I don't really feel like doing), unless perhaps I could find some framework stuff I could reuse. I sort of doubt this since it'd need to be able to run on both a j2me device and on some webserver but perhaps someone could prove me wrong? Also, this might require some custom server and being able to run on a normal webserver would be nice for convenience.

So how about it, anyone have any suggestions for me? Right now I'm leaning towards the .net webservice approach and hosting it myself and not caring about the bandwidth costs but if someone has any good ideas (particularly for the bandwidth problem) I'd love to hear them. My friend and I are both experienced programmers so learning new stuff like a programming language isn't much of a problem although my friend can be a bit stubborn sometimes and wants to stick with stuff he already knows.. We both work as programmers and since we are doing this on our free time we'd like to minimize the tedious parts of programming.

Encryptic
May 3, 2007

I don't know if this is the right place to ask - but if anyone's familiar with Flash:

Is there a way to make a roll-over/roll-off event respond faster in Flash? I'm working on a menu that fades in when you roll-over a button. The roll-over part works fine, but the roll-off doesn't work if you roll-off the button itself too fast - you have to slowly roll-off for it to trigger the menu fade-out. I've tried a bunch of things and nothing seems to increase the response time, aside from cranking up the frame rate, which isn't really a usable solution since the menu effect is too fast to see in that case.

hey mom its 420
May 12, 2007

Maybe you can give it an onEnterFrame event where it checks if the button is in its roll-over state but the mouse is not on it. If that's the case, then fire the roll-off event.

Adbot
ADBOT LOVES YOU

Inspector Chan
Jul 9, 2002

I like the third option: I keep the disc, and throw you both off.
I need a little help with regular expressions. I'm trying to figure out how to find strings with only one word. This is for SQL but I guess it's just more of a regexp question. Here's what I have:

code:
SELECT title 
FROM movies
WHERE REGEXP_LIKE(title,'[^\s][A-Z][\s]$');
Here's some of the titles:

code:
THE DAY THE EARTH STOOD STILL  
THEM  
2001: A SPACE ODYSSEY  
FORBIDDEN PLANET  
METROPOLIS  
THE TERMINATOR  
I've tried every combination I can think of and I'm stumped. Any help? And any suggestions on where to go to learn this? I have about 8 tabs open and I'm still stuck.

Solution Found:

code:
SELECT title 
FROM movies
WHERE REGEXP_LIKE(title,'^[A-Z0-9]*[A-Z0-9]$');

Inspector Chan fucked around with this message at 06:49 on Sep 29, 2008

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply